Does Enum
expand by compiler into a class declaration in Java?
Does Enum
expand by compiler into a class declaration in Java?
It can be understood that a Enum
is a class with special characteristics. The compiler will always treat this type in a specific way.
switch
, toString()
, I think a few more things. So you can say that yes, at least in the end it gives more or less the same thing. I do not know if the specification says something about how it should be done, but it's a possible way, even though I do not know any specific instructions in the bytecode of the JVM that deals with enumerations, so it has to be simulated in some other way and the class seems appropriate.
There is a question in the OS whose answers confirm this .