Why do you prefer indirect general imports for the actual class?

Using eclipse if I write this interface in a package mypack:

package mypack;
public interface MyInterface<A>{
  public interface Test{
    void sayHi();
  }
}

And if I write this class in the package no .

public class Test implements mypack.MyInterface<mypack.MyInterface.Test> {
  private Test test = new Test();
}

Eclipse gives me an error at compile time, I have to implement the method sayHi().

I do not see a way out!

If I Ctrl+ LMBto the field type test, it will lead me to the class.

Error reported

A small error is reported here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=488077

+4
source share
1 answer

What's going on here,

Test test = new Test();

Test MyInterface, .

JLS, , , .

: MyInterface .

interface MyInterface {
    interface Test {
    }
}

class Test extends MyInterface {
    Test test = new Test(); // thinks this is the MyInterface.Test
}

BTW: , .

JLS 7.4.2

Java SE .

+2

Source: https://habr.com/ru/post/1629520/


All Articles