I have a class like
@SomeAnnotation(Outer.Inner.class)
enum Outer {
A, B, C;
private static class Inner {...}
}
which works fine in Eclipse, but javac complains about private access. Which compiler is right?
According to what I know, all access restrictions get ignored as long as the access occurs in the same source file.
Accessibility in the class declaration is different than from within the class – no symbols in the declaration can refer to private members. This is because the information given by the declaration must inherently be available to at least the rest of the package.
For example, consider a package-private class
Outer:The above is invalid because other members of the package would not have access to
Inner, even though they must be able to accessOuterand know what it is via its declaration. Similar logic can be applied to your situation.I’m not sure why Eclipse allowed it, but I would say javac is correct and NetBeans seems to agree.