This is a homework question, so I'm not looking for a direct answer. I need a push in the right direction. I'm simply 开发者_JAVA技巧not understanding the question. My answer to this was "The values are, in fact, instances of their own enumeration type." Which came back incorrect. I'm looking at the API now...is this referring to the methods listed in the methods summary?
I'm noticing from this page that modifier types for Java in general refer to access control (private, public, protected) and non-access modifiers (static, final, abstract, volatile).
I'm putting public, protected for my next answer as I see those two listed within the API for access control. Am I thinking about this correctly?
Got back my homework, turns out I was correct.
The modifiers for each constant are implicitly declared, as mentioned in the Java Language Specification, §8.9 Enums. As a corollary, consider which modifiers are associated with all-upper-case identifiers in the widely used Google Java Style or Java Coding Style Guide?
As the homework should be over a while ago and for anyone like me looking for a quick answer:
public static final
For each enum constant c declared in the body of the declaration of E, E has an implicitly declared
public static final
field of type E that has the same name as c. The field has a variable initializer consisting of c, and is annotated by the same annotations as c.
(taken from trashgod's link: Java Language Specification, §8.9 Enums)
I believe you are correct. In java, all the values in an Enum have the type of that Enum. Instead of being treated like magic values as they are in many other languages, they are instances of a type, a very beautiful OO way of thinking about things.
"The values are, in fact, instances of their own enumeration type."
This is factually correct, but it does not answer the question you were asked about the implicit modifiers for enum values. That is why it is the wrong answer.
精彩评论