Why it is not possible to override mutable variable in scala ?
class Abs(var name: String){
}
class AbsImpl(override var name: String) extends Abs(name){
}
I believe that the intent was simply to set the value of the inherited var name
. This can be achieved this way (without override var
):
class Abs(var name: String){
}
class AbsImpl(name: String) extends Abs(name){
}
The ambiguity arises from the local var name: String
in AbsImpl
that is named after the inherited var name: String
from Abs
. A similar code, less syntactically ambiguous but also less elegant would be:
class Abs(var name: String){
}
class AbsImpl(name_value: String) extends Abs(name_value){
}