如何访问超类的多个特征之一?

时间:2011-09-23 09:08:09

标签: scala

我有一个特征是从其他一些特征实现的。这些特征中的每一个都会覆盖超级行为的行为,并且混合到一个类中:

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.name
}

现在,在课程C中,我想要访问不是最后一个混合特征的行为,而是访问其中一个特征的行为。这可能吗?

1 个答案:

答案 0 :(得分:26)

可以将超级调用专门化为特定的特征:

class C extends T with T1 with T2 {
  def printName = super[T1].name
}