As we all know, multiple interfaces
can implemented in Java. Does the order of their implementation matter? I mean, is implementing B, C is same as C, B in Java 8
? My tests show order does matter - but can anyone explain the logic behind this?
public interface A {
public default void display() {
System.out.println("Display from A");
}
}
public interface B extends A {
public default void display() {
System.out.println("Display from B");
}
}
public interface C extends A {
public void display();
}
public interface D extends B, C {
}
The above code works fine. If I change the order B, C
to C, B
, it will give an error: The default method display() inherited from B conflicts with another method inherited from C.
public interface D extends C, B {
}
Edit
I am using Eclipse(Mars). JDK jdk1.8.0_51
. JRE jre1.8.0_60
.