Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

java - ctrl-click goes to the declaration of the method I clicked. For interfaces with one implementation, how can I just directly go to that implementation?

I often have to debug java code which was written so that there is an interface and exactly one implementation of that interface.

For instance there would be an interface Foo with exactly one implementation called FooImpl. In the following code if I ctrl-click on doThings it'll jump to Foo.java when I actually want to go to FooImpl.java to see the implementation.

public void doStuff(Foo foo) {
    foo.doThings();
}   

When I end up at the interface I have to use ctrl-shift-r to open up FooImpl. It'd be really nice if I could do something lick ctrl-alt-click on doThings and end up inside FooImpl.java. If there are multiple implementations in the workspace then perhaps it would just pop up a box telling me what they are.

Is there a plugin or existing function in eclipse that does this? I know that I could go to Foo.java and then get the hierarchy and go to the implementation, but that's more clicks than are necessary when there is exactly one implementation of an interface.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. Move the cursor to the method call
  2. Press Ctrl + T
  3. Select your desired implementation
  4. Hit Enter

This also works if there are several implementors.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...