Consider the following:
//Fooable.java
public interface Fooable {
public default void foo() {
System.out.println("Fooable::foo");
}
//Lots of other non-default methods...
}
//MyFooable.java
public class MyFooable implements Fooable {
@Override
public void foo() {
System.out.println("MyFooable::foo");
}
//implements other methods in Fooable...
}
//MyAdvancedFooable.java
public class MyAdvancedFooable extends MyFooable {
@Override
public void foo() {
Fooable.super.foo();
System.out.println("MyAdvancedFooable::foo");
}
public static void main(String[] args) {
new MyAdvancedFooable().foo();
}
}
As you can see, I want to call foo()
in Fooable
from MyAdvancedFooable
(a subclass of MyFooable
). However, when I try to compile, I get the following error:
MyAdvancedFooable.java:4: error: not an enclosing class: Fooable Fooable.super.foo();
if I try MyAdvancedFooable extends MyFooable implements Fooable
I get the following:
MyAdvancedFooable.java:4: error: bad type qualifier Fooable in default super call Fooable.super.foo(); method foo() is overridden in MyFooable
How can I resolve this problem without having to create a new anonymous implementation of Fooable?