Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to navigate to implementing class from interface in Eclipse? [duplicate]

Tags:

java

eclipse

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.

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?

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

like image 672
Eric Wilson Avatar asked Jun 21 '11 19:06

Eric Wilson


3 Answers

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

like image 195
javawebapps Avatar answered Nov 07 '22 01:11

javawebapps


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"...

like image 35
Tonny Madsen Avatar answered Nov 07 '22 01:11

Tonny Madsen


Select the method and press Ctrl+T.

Also clicking the gray up-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.

like image 43
Nick Avatar answered Nov 07 '22 02:11

Nick