Constructor Parameters of 'case class' are Read Only

scala> case class MyClass(arg1:Int, arg2:Int)
defined class MyClass

scala> val obj = MyClass(1, 2)
obj: MyClass = MyClass(1,2)

scala> obj.arg1
res17: Int = 1

scala> obj.arg1 = 4
<console>:48: error: reassignment to val
 obj.arg1 = 4
 ^

No comments:

Post a Comment