当前位置: 代码迷 >> 综合 >> SCALA的例子详解
  详细解决方案

SCALA的例子详解

热度:88   发布时间:2024-01-15 10:30:08.0
 scala是一门函数式的面向对象的语言,它运行在java虚拟机上。
eg1、
示例代码:
scala>var helloWorld = "hello" + " world" 
println(helloWorld)
scala>val again = " again" 
helloWorld = helloWorld + again
println(helloWorld)
输出:
hello world hello world again eg2、定义函数 def
示例代码:
def square(a: Int) = a * a
def squareWithBlock(a: Int) = { a * a}
val squareVal = (a: Int) => a * a (这里是将Int整数a映射为a*a的函数)</