I'm trying to use mutators on a var that has been declared in a super-class :
---
class Something(val name:String,var age:Int) {
}
class SomethingElse(name:String, ageInitial: Int) extends Something(name, ageInitial) {
private var ageInternal = ageInitial
override def age:Int = {
println ("getName call!")
ageInternal
}
override def age_=(value:Int) = {
println ("Setting age to " + value)
ageInternal = value
}
}
---
This won't compile. The compiler complains about 'method age cannot override a mutable variable'. Is this correct behavior? I mean: coming from a java background, i'm used to it being possible to override your getter/setter methods in a sub-class. It should not be necessary to modify the super-class to allow this (as i've read in
this post). Or is something wrong with my code?
Mark