scala 变量:

  val : 声明时,必须被初始化,不能再重新赋值。

scala> test = "only1"
<console>:11: error: not found: value test
test = "only1"
^
<console>:12: error: not found: value test
val $ires0 = test
^

    var :可被多次赋值。

scala> var test2 = "vartest"
test2: String = vartest

scala> var test2 = "vartest1"
test2: String = vartest1

  

05-11 20:37