22

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.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?

Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
kiritsuku
  • 52,967
  • 18
  • 114
  • 136

1 Answers1

28

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
}
kiritsuku
  • 52,967
  • 18
  • 114
  • 136