Types of Enumerations as Described in Joshua Bloch's "Effective Java"

See link. Mr. Bloch says regarding Enums

Javas enumeration types are classes that export one instance for each enum constant through a public static destination field.

I read the Enum Class documentation, but there was no public static final field , then how the above statement is executed. Please explain. Thanks

+5
java enums effective-java
source share
2 answers

Create a Test.java file and write Test enum :

 public enum Test { Hello } 

compile this class: javac Test.java and use javap Test to get the compiled class:

 public final class Test extends java.lang.Enum{ public static final Test Hello; public static Test[] values(); public static Test valueOf(java.lang.String); static {}; } 

and you can see that the Test class extends from Enum and has a public static final Hello field.

+13
source share

Enum is the base class for all enumerations. It does not contain constants. What contains constants are concrete enumeration classes. See, for example, the documentation for listing Locale.Category . It contains public static trailing fields for each enumeration constant: DISPLAY and FORMAT.

+3
source share

All Articles