Community
Participate
Working Groups
The following code produces a compile-time error because enumerations are implicitly static, and thus cannot appear inside a non-static member class declaration: public class TestClass { public class InnerClass { public enum InnerEnum { A, B, C } } } The error message given by the Eclipse compiler is: The member type InnerEnum cannot be declared static; static types can only be declared in static or top level types This may cause confusion with normal Java programmers because, not having used the static keyword, they may not realize that enumerations are static. It also implies that declaring InnerEnum as non-static would solve the problem (which is impossible). The javac compiler produces the following message, which I feel is more friendly on both counts: TestClass.java:20: enum declarations allowed only in static contexts
Agreed.
Actually, our error message reads already: The member enum InnerEnum must be defined inside a static member type It clearly tells about enum type.