Is it possible to override val
s or def
s in the subclass's constructor? I want to initialize (or set) trait's members or abstract class's members in the subclass's constructor as parameters.
The following is an example.
trait A { def memberDef: Int => String val memberVal: String } class B( override val memberDef: Int => String, override val memberVal: String) extends A { ... }
Here, class B
's memberDef
overrides trait A
's memberDef
, and class B
's memberVal
overrides trait A
's memberVal
.
When I compiled this, there was no error. However, I want to know whether there are any bugs in this implementation, or whther there is a better implementation.