如何找到哪些类在 Eclipse 中实现了特定的接口?

我有一个具有许多依赖项的应用程序作为 JAR 文件。出于某种原因,我需要反编译其中一个库并用 Eclipse 打开它。对于项目中的给定接口,是否有方法查找实现它的类?这可能是我还没有反编译的其他库中实现的接口的情况。这种类型的课程有可能做到这一点吗?

70220 次浏览

Try Ctrl+T after selecting the classname; should work in Java Perspective.

Right-click on the interface, and choose "Open type hierarchy". Then click on "Show the subtype hierarchy".

You can "Show Type Hierarchy" on the item (Right Click to choose this option or press F4 when the item is highlighted)*.

However, this will list only items in those projects that are referred ("dependent"). Not in others.

So if you have decompiled a jar, and there is another jar that you have not decompiled, then the implementations (of the interface) in that jar will not be listed.

Also, say you have decompiled a jar as a project and there is another project that is referring to the jar, and not the decompiled project, implementations in that will also not be listed.

So you will have to decompile all jars and add them as projects (and add references via "Java Build Path") to make sure all the implementations in the jars of your choice are listed.

* Quick type Hierarchy, ctrl + T will show a similar structure in a tooltip/autocomplete kind of panel. But the complete type hierarchy is more useful for the type of analysis you are intending to do.

Or right-click and select Quick Type Hierarchy for a pulldown menu of extending interfaces and implementing classes.

There is radio-button "Implementors" in Java Search.

Ctrl + H (Search Option) Open Java Search perspective and, enter the interface name, click Implementors radio button and you will find which classes implement a particular interface. Same as answer from stackexchanger above

Select the class name, then 'F4' in Eclipse (Windows environment)