10
Let's say we have a class with a 'name' property:
class SuperFoo(var name: String)
If I wish to override this, to eg add some locking around the calls:
class SubFoo(n: String) extends SuperFoo(n) {
val lock = new ReentrantLock
override def name(): String =
{
lock.lock
try {
super.name
} finally {
lock.unlock
}
}
override def name_=(arg: String): Unit = {
lock.lock
try {
super.name = arg
} finally {
lock.unlock
}
}
}
The above produces a compilation error:
super may be not be used on variable name
Any ideas how to correctly implement this? (i.e. override the getter & setter to add locking around them). Thanks!