What are the default modifier fields for an enum type?

This is a homework question, so I am not looking for a direct answer. I need a push in the right direction. I just do not understand the question. My answer to this question is: "Values ​​are, in fact, instances of their own enumeration type." Which came back wrong. I'm looking at the API now ... does this apply to the methods listed in the method summaries?

I notice from this page that modifier types for Java generally relate to access control (private, public, protected) access modifiers (static, finite, abstract, unstable).

I am posting a publication protected for my next answer as I see the ones listed in the access control API. Am I thinking about it right?

I'll be back home, it turned out that I was right.

+3
source share
4 answers

Modifiers for each constant are implicitly declared, as specified in the Java Language Specification, §8.9 Enums . As a result, consider which modifiers are associated with all uppercase identifiers in the widely used Google Java Style or Java Coding Style Guide ?

+3
source

I think you're right. In java, all values ​​in Enum are of the type of this Enum. Instead of being perceived as magical values, as they are in many other languages, they are instances of the type, a very beautiful way of thinking about things.

0
source

", , ."

, , , . .

0

Since homework should be finished some time ago, and for those who love me, they are looking for a quick answer:

public static final

For each constant c enum declared in the body of the declaration E, E has an implicitly declared field of public static finaltype E that has the same name as c. The field has a variable initializer consisting of c and is annotated with the same annotations as c.

(taken from trashgod reference: Java Language Specification, §8.9 Enumerations )

0
source

Source: https://habr.com/ru/post/1790129/


All Articles