I'm totally lost on why that won't work:
interface Test {
default void doMagic() {
System.out.println("Abracadabra");
}
}
class TestImpl implements Test {
}
class SpecialTestImpl extends TestImpl {
public void doMagic() {
Test.super.doMagic(); // Error: No enclosing instance of the type Test is accessible in scope
}
}
Is this some weird Eclipse error message (it's not able to cope with Lamdas either, so maybe Mars isn't entirely Java 8 ready, yet)?
I can fix it by letting SpecialTestImpl
implement Test
directly (which yields a warning, because it's unnecessary) or overriding the method in TestImpl
(which yields a warning for the same reasons).
So why wouldn't I be able to call the super method?
My guess was because if I was able to call Test.super.doMagic()
directly, implementing the method in TestImpl
would break the API for SpecialTestImpl
even though it shouldn't. But that is also true if I let SpecialTestImpl
implement Test
and call the default method that way.