How to call an overridden data item in Scala? Here is an example from a worksheet - I would like to do something like:
trait HasWings {
def fly() = println("I'm flying!")
val wingType = "Thin"
}
class Bee extends HasWings {
override def fly() = {
println("Buzzzz! Also... ")
super.fly()
}
override val wingType = "Translucent and " + super.wingType
}
val bumble = new Bee()
bumble.fly()
println(s"${bumble.wingType}")
But I get an error super may not be used on value wingType. How can I override a data member while still accessing it? There are workarounds, for example:
- Do not override superclass value
- Declaring a superclass value as a method
But I am wondering if I can get an override and access to the data member in the superclass.
Thanks!
source
share