Please see this link. Regarding Enums, Mr. Bloch says
Java’s enum types are classes that export one instance for each enumeration constant via a public static final field.
I read the Enum Class documentation but there was no public static final field, then how does the above statement hold true. Please explain. Thanks
Create a
Test.java
file and writeTest enum
:compile this class:
javac Test.java
,and usejavap Test
to get the compiled class:and you can see the
Test
class extends fromEnum
and it has thepublic static final Hello
field.Enum is the base class for all enums. It doesn't contain constants. What contains constants are the concrete enum classes themselves. See for example the documentation for the enum Locale.Category. It does contain public static final fields for each enum constant: DISPLAY and FORMAT.