How does Java 8′ new default interface model works (incl. diamond, multiple inheritance, and precedence)?

There is a perfect explanation at Java Lambda FAQ.
Here is a citation from What about the diamond problem? article there:

interface A {
    default void m() { ... }        
}
interface B extends A {}
interface C extends A {}
class D implements B, C {}

In the initial case (the code above), the implementation of m inherited by D is unambiguously that defined by A — there is no other possibility. If the situation is changed so that B now also declares a default implementation of m, that becomes the implementation that D inherits by the “most specific implementation” rule. But if both B and C provide default implementations, then they conflict, and D must either use the syntax X.super.m(…) to explicitly choose one of them, or else redeclare the method itself, overriding all supertype declarations.

Be sure to check out previous article on rules of resolving conflicting method declarations and other articles on Java Lambda project — they are quite good.

Leave a Comment