Technically one could indeed view enums as a class with a bunch of typed constants, and this is in fact how enum constants are implemented internally. Using an
enum however gives you useful methods (Enum javadoc) that you would otherwise have to implement yourself, such as
There is also
.values() to iterate over the list of values
- Type safety and value safety.
- Guaranteed singleton.
- Ability to define methods.
- Ability to use values in
casestatements without qualification.
- Built-in sequentialization of values via
- Serialization by name not by value, which offers a degree of future-proofing.
Another post about getting enums by class name