在IntelliJ IDEA中导航到声明,类型声明,实现和有什么区别?

时间:2019-10-23 10:54:00

标签: java debugging intellij-idea navigation

The official documentation  我不清楚要提取它们之间的真正差异。 为了更容易理解,有人可以举一个例子或场景吗?

enter image description here

1 个答案:

答案 0 :(得分:3)

请考虑以下示例代码。光标位于m的{​​{1}}或同一行的m.aMethod();处。

Main.java

aMethod

MyInterface.java

public class Main implements MyInterface {

  public static final void main(String args []) {
    MyInterface m = new Main();
//              ^1

    m.aMethod();
//  ^ Declarations will bring you to 1, the declaration of the variable (m)
//    Type Declaration will bring you to 2, the declaration of the type of the variable (MyInterface)
    m.aMethod();
//       ^ Declaration will bring you to 3, the declaration of the method in the type (MyInterface) of the variable
//         Implementation(s) will bring you to 4, the declaration of the method implementing the interface method
  }

  public void aMethod() {
//            ^4
  }
}