Problem with Interface in JDK 8.0

Since java class can implement multiple interfaces and each interface can define default method with same method signature, therefore the inherited methods can conflict with each other.

Consider the below example.,

 

The above code will fail to compile with the following error:

java:class Impl inherits unrelated defaults for defaultMethod() from types InterfaceA and InterfaceB.

In order to fix this class, we need to provide defalut method implementaion.

We can choose any default implementation or both as part of our new method.

 

Leave a Reply

Your email address will not be published. Required fields are marked *