Scala官网:https://docs.scala-lang.org/tour/basics.html
val(Values)
Named results, such as x
here, are called values. Referencing a value does not re-compute it.
x = 3 // This does not compile.
var(Variables)
Variables are like values, except you can re-assign them. You can define a variable with the var
keyword.
var x = 1 + 1
x = 3 // This compiles because "x" is declared with the "var" keyword.
println(x * x) // 9