Consider the code below:
trait A {
def work = { "x" }
}
trait B {
def work = { 1 }
}
class C extends A with B {
override def work = super[A].work
}
Class C
won't compile in scala 2.10, because of "overriding method work in trait A of type => String; method work has incompatible type".
How to choose one specific method?
I'm afraid there is no way to do that. The super[A].work
way works only if A
and B
have the same return types.
Consider this:
class D extends B
....
val test: List[B] = List(new C(), new D())
test.map(b => b.work) //oops - C returns a String, D returns an Int