Calling default method in interface when having conflict with private method Calling default method in interface when having conflict with private method java java

Calling default method in interface when having conflict with private method


Update: Seems like it's really a bug.

A class or super-class method declaration always takes priority over a default method!

default hello(...) method from the Myinterface allows you to write without errors:

ClassB b = new ClassB();b.hello();

Until runtime, because at runtime hello(...) method from the ClassA takes the highest priority (but the method is private). Therefore, IllegalAccessError occurs.

If you remove the default hello(...) method from the interface, you get the same illegal access error, but now at compile time.