This content has been marked as final. Show 4 replies
Taking a look over the JSL, it would appear that enums could not be inner classes as "Inner classes may not declare static members" [§8.1.3|http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1.3].
Scanning [§8.9|http://java.sun.com/docs/books/jls/third_edition/html/classes.html#301020] and I found: "Nested enum types are implicitly static. It is permissable to explicitly declare a nested enum type to be static."
mlk wrote:No, enums are not normal classes, and compared to "inner classes" is it what thy call static nested classes that is most close. But it is still in a way a class, one that not may be explicitly instantiated and sub classed, but one that may have its own static and/or instance methods. I often use enums with methods.
enums could not be inner classes
I have not looked in JLS very much, I actually thought it was a bit out-of-date in lack of maintenance, but it is apparently not. And "Nested enum types are implicitly static" seems to be how to treat static vs. non static enums. That is they are always static whether declared so or not. Like methods in an interface that always are public static whether declared that or not. That would then make the rules clear, they may only access static members in their enclosing class like a static nested class. Which also is how it works in my little code sample above.
I then guess this question is answered now, and thanks for your reply!
JonnyAndersson wrote:For your penance, read one section each night before bed, for a week.
I have not looked in JLS very much, I actually thought it was a bit out-of-date in lack of maintenance, but it is apparently not.
JonnyAndersson wrote:Enums are classes with knobbly bits. On of the knobbly bits is they have a bunch of static constants. Inner classes can not have static members. Thus a enum can not be an inner class.
No, enums are not normal classes,
bit out-of-date in lack of maintenance,No and if they were it would be a very bad thing.