I understand if a class overrides a default method, you can access the default method in the following manner
interface IFoo {
default void bar() {}
}
class MyClass implements IFoo {
void bar() {}
void ifoobar() {
IFoo.super.bar();
}
}
But what about the case where an interface overrides a default method? Is the parent method available in any way?
interface IFoo {
default void bar() {}
}
interface ISubFoo extends IFoo {
// is IFoo.bar available anywhere in here?
default void bar {}
}
class MyClass implements ISubFoo {
// is IFoo.bar available anywhere in here too?
public static void main(String[] args) {
MyClass mc = new MyClass();
mc.bar(); // calls ISubFoo.bar
}
}
The verbiage Java uses for default methods is similar to that for classes, otherwise it's confusing/misleading. Subinterfaces "inherit" default methods, and can "overwrite" them. So it seems IFoo.bar should be accessible somewhere.
super.superin Java. You can never access a method that was overridden in the parent, regardless of wether it's aclassor adefaultmethod on aninterface.