eclipsegenericsjavac

Bug in eclipse compiler or javac?


Who is right? Eclipse or javac?

--------------- c/v/A.java ---------------

package c.v;
public class A<T> {
}

--------------- c/v/B.java ---------------

package c.v;
public class B extends A<B.Secret> {
  private class Secret {};
}

Eclipse compiles B.java just fine.

Javac has a problem.

$ javac c/v/B.java
c/v/B.java:3: c.v.B.Secret has private access in c.v.B
public class B extends A<B.Secret> {
                           ^
    1 error

Solution

  • The relevant parts of the Java Language Specification must be:

    §8.1.4: [...] The ClassType must name an accessible (§6.6) class type, or a compile-time error occurs.

    §6.6.1: [...] A member (class, interface, field, or method) of a reference (class, interface, or array) type or a constructor of a class type is accessible only if the type is accessible and the member or constructor is declared to permit access:

    So since the ClassType is not within the body of the class, B.Secret is not accessible at this location, so A<B.Secret> is not accesible, so a compile-time error should occur.