valとvar
valが不変でvarが可変
//valでコンストラクタを定義 scala> class Person(val name:String) defined class Person scala> val p = new Person("Andy") p: Person = Person@72aa81 scala> p.name res0: String = Andy scala> p.name="John" <console>:6: error: reassignment to val p.name="John" ^
不変なので読み取りのみ
//varでコンストラクタを定義 scala> class Person(var name:String) defined class Person scala> val p2 = new Person("Andy") p2: Person = Person@e57f16 scala> p2.name res1: String = Andy scala> p2.name="John" scala> p2.name res2: String = John
読み書きオッケー