Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access one of multiple traits of superclass?

Tags:

scala

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?

like image 935
kiritsuku Avatar asked Sep 23 '11 09:09

kiritsuku


1 Answers

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
}
like image 116
kiritsuku Avatar answered Nov 08 '22 09:11

kiritsuku