Short of renaming the constructor parameter in the primary constructor of class B
, what change can I make to the following code (without changing its function) so that Scala will compile it successfully?
Example:
class A(var a: Int)
class B(a: Int) extends A(a) {
def inc(value: Int) { this.a += value }
}
Error:
$ scala construct.scala
construct.scala:3: error: reassignment to val
def inc(value: Int) { this.a += value }
^
one error found
I raised this question in an answer to my previous question, "In Scala, how do you define a local parameter in the primary constructor of a class?".