开发者

How to access one of multiple traits of superclass?

开发者 https://www.devze.com 2023-04-06 18:03 出处:网络
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:

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消