Is there an effective way to make transparent the related interface of an overridden method

WolfiG :

I have a class implementing multiple interfaces. Via the interfaces I have many overridden methods in the code originating from the various interfaces:

public class myClass implementing IF1, IF2, IF3, .... () {
....
@Override
method1 () { ...} <-- from IF2
method2 () { ...} <-- from IF1
method3 () { ...} <-- from IF2
method4 () { ...} <-- from IF2
method5 () { ...} <-- from IF3
method6 () { ...} <-- from IFxy
}

I have repeatedly the issue that I want to know which interface the overriding mathod belongs to and to navigate to the corresponding interface. Is there an elegant way to make the method-to-interface relation visible/transparent?

All the best WolfiG

DodgyCodeException :

It's not possible to make it explicit in Java code. Contrast this with C# for example:

class MyClass : Interface1, Interface2 {
    override Interface1.Method1 {...}
    override Interface2.Method1 {...}
}

Notice that in the C# code above, there are two methods with the same name but overriding different interfaces. This is not possible in Java. If two implemented interfaces have the same method, you can only have one method in Java which overrides the method of both interfaces at once. Therefore, it's not really possible to say in code which interface a certain method is overriding. It's overriding all methods of the same name in all interfaces.

However, you can add a comment. Also, if you add a Javadoc comment, then the generated documentation will automatically say "Specified by method xxx in interface yyyy."

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=128209&siteId=1