I understand that the class overrides the default method, you can access the default method as follows
interface IFoo {
default void bar() {}
}
class MyClass implements IFoo {
void bar() {}
void ifoobar() {
IFoo.super.bar();
}
}
But what about when the interface overrides the default method? Is the parent method available in any way?
interface IFoo {
default void bar() {}
}
interface ISubFoo extends IFoo {
default void bar {}
}
class MyClass implements ISubFoo {
public static void main(String[] args) {
MyClass mc = new MyClass();
mc.bar();
}
}
The words used by Java for default methods are similar to those used for classes, otherwise it will be confusing / misleading. Subinterfaces "inherits" default methods and can "overwrite" them. So it seems that IFoo.bar should be accessible somewhere.
source
share