Add new method to an interface which is directly implemented by many classes

interface, java

Solution

Is there any way to add a new method to java interface without modifying the classes that are implementing it.

No.

condition is that I should not introduce new interface

If the condition also includes not modifying the many classes that directly implement the interface, you have been given an impossible task.

This is the reason why interfaces are often accompanied by abstract `Adapter` classes, that implement all the methods in a do-nothing way. Implementation classes then extend the adapter rather than implementing the interface, so that if you need to add an interface you only need to modify the interface and the adapter.

Problem

I have a small question on java interfaces Is there any way to add a new method to java interface without modifying the classes that are implementing it. condition is that I should not introduce new interface

Original source