Luk Aron
Luk Aron

Reputation: 1415

What's the difference between navigating to Declaration, Type Declaration, Implementation in IntelliJ IDEA?

The official documentation is unclear for me to extract the real difference between them. Could someone give an example or scenario for the sake of easier understanding?

enter image description here

Upvotes: 0

Views: 267

Answers (1)

Roger Gustavsson
Roger Gustavsson

Reputation: 1709

Consider the following example code. Your cursor is at m in m.aMethod(); or at aMethod in the same line.

Main.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
  }
}

MyInterface.java

public interface MyInterface {
//               ^2
  public void aMethod();
//            ^3
}

Upvotes: 4

Related Questions