I'm wanting to do something like this:
class A (var updateCount: Int) {
}
class B (val name: String, var updateCount: Int) extends A(updateCount) {
def inc(): Unit = {
updateCount = updateCount + 1
}
}
var b = new B("a", 10)
println(b.name)
println(b.updateCount)
b.updateCount = 9999
b.inc
println(b.updateCount)
but the compiler doesn't like it.
(fragment of extend.scala):5: error: error overriding variable updateCount in class A of type Int;
variable updateCount needs `override' modifier
class B (val name: String, var updateCount: Int) extends A(updateCount) {
Adding override on updateCount doesn't work either. What's the clean way to do this?