How to access one of multiple traits of superclass?
I have a trait which is implemented from some other traits. Each of these traits override the behavior of the supertrait and are mixed-in to a class:
trait T {
def name = "t"
}
trait T1 extends T {
abstract override def name = "t1"
}
trait T2 extends T {
abstract override def name = "t2"
}
class C extends T with T1 with T2 {
def printName = super.开发者_C百科name
}
Now, in class C
I want to access the behavior not of the last mixed-in trait but the behavior of one of these traits. Is this possible?
It is possible to specialize the super-call to a specific trait:
class C extends T with T1 with T2 {
def printName = super[T1].name
}
精彩评论