You can do the following:
class A extends B with C {
super[B].foo()
}
This will only compile if B
implements foo
. Use with caution though as it (potentially) introduces some unintuitive coupling. Further, if A
overrides foo
, still B
's foo
will be called.
One IMHO valid use case is conflict resolution:
trait B { def foo() = println("B") }
trait C { def foo() = println("C") }
class A extends B with C {
override def foo() = super[B].foo()
}
If you want to make sure B
declares foo
, you can use type ascription:
class A extends B with C {
(this:B).foo()
}
This will only compile if B
declares foo
(but it might be implemented in C
or A
).