如何从 Eclipse 的接口导航到实现类?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6430825/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:29:05  来源:igfitidea点击:

How to navigate to implementing class from interface in Eclipse?

javaeclipse

提问by Eric Wilson

Suppose I have:

假设我有:

interface Foo {
  void doStuff();
}

class FooImpl implements Foo {
  public void doStuff() {
    // stuff
  }
 }

When I see myFoo.doStuff()in my code, if my cursor is over doStuff(), pressing F3 will take me to the doStuff()method in the interface Foo. Of course, I often am much more interested in the implementation of this method, not just the signature.

当我myFoo.doStuff()在我的代码中看到时,如果我的光标在上面doStuff(),按 F3 会将我带到doStuff()界面中的方法Foo。当然,我往往对这个方法的实现更感兴趣,而不仅仅是签名。

Does Eclipse have an easy way to navigate from a declaration of a method in an interface to the implementation of that method in the implementing class?

Eclipse 是否有一种简单的方法可以从接口中的方法声明导航到实现类中该方法的实现?

In my case, there will not be ambiguity about what the implementing class is.

就我而言,实现类是什么不会有歧义。

回答by javawebapps

Highlight the method name, and press either CTRLTor F4. You'll see a type hierarchy, but linked to the method rather than the containing classes. Select the desired implementation class.

突出显示方法名称,然后按CTRLTF4。您将看到一个类型层次结构,但链接到方法而不是包含的类。选择所需的实现类。

回答by Tonny Madsen

Or - if you have enabled Hyperlinking (see the preference page with that name) - you can press Control (or Command on MacOS) and click on the method name. It will then show a menu with "Open Declaration" and "Open Implementation"...

或者 - 如果您已启用超链接(请参阅具有该名称的首选项页面)- 您可以按 Control(或 MacOS 上的 Command)并单击方法名称。然后它会显示一个带有“开放声明”和“开放实施”的菜单......

回答by Nick

Select the method and press Ctrl+T.

选择方法并按 Ctrl+T。

Also clicking the grayup-arrow on the left hand side of the editor close to the line numbers will take you to a method declaration in an interface. If that same arrow is green, it will take you to a method definition in a super class.

同时单击gray编辑器左侧靠近行号的向上箭头将带您到接口中的方法声明。如果相同的箭头是green,它将带您到超类中的方法定义。