В чем разница между переходом к декларации, типу декларации и реализации в IntelliJ IDEA? - PullRequest
0 голосов
/ 23 октября 2019

Официальная документация Мне неясно извлечь реальную разницу между ними. Может ли кто-нибудь привести пример или сценарий для облегчения понимания?

enter image description here

1 Ответ

3 голосов
/ 23 октября 2019

Рассмотрим следующий пример кода. Ваш курсор находится на m в m.aMethod(); или на aMethod в той же строке.

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
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...