Please look at this link. In his book Effective Java, Joshua Bloch says
Note that the Operation constants are put into the stringToEnum map from a static block that runs after the constants have been created.
Trying to make each constant put itself into the map from its own constructor would cause a compilation error
. This is a good thing, because it would cause a NullPointerException if it were legal.
Enum constructors aren’t permitted to access the enum’s static fields, except for compile-time constant fields.
This restriction is necessary because these static fields have not yet been initialized when the constructors run.
I have two questions
- Can Enums have separate constructors for each constant?
- Why are compile time constant fields accessible in constructors but not static fields?
Thanks