Java - solving the diamond problem with default methods in interfaces
Prior to java 8
Prior to java 8, Java was not subject to the Diamond problem risk. The reason is, it did not support multiple inheritance. Java does not allow multiple inheritance for classes, only for interfaces. In the past, this prevented the ‘diamond problem’ more typically seen in C++ as it is only possible to inherit an implementation from the single parent class.
After java8
After java8, Java is subject to the Diamond problem.
Java 8 introduces default methods on interfaces. If A,B,C are interfaces, B,C can each provide a different implementation to an abstract method of A, causing the diamond problem. Either class D must reimplement the method (the body of which can simply forward the call to one of the super implementations), or the ambiguity will be rejected as a compile error.
With Java 8, a class can now inherit a method implementation from either its parent class or any of its interfaces, increasing the chance for the compiler to reject the compilation.
See how the diamond problem due to default methods in interfaces since (java 8) is solved in Java - default methods in Interfaces