Differences:
- Enums extend
java.lang.Enumand gain all of its nice features:- Automatic singleton behaviour through correct serialization
- Automatic human-readable
.toStringmethod on enum values without the need to duplicate your enum names .nameand.ordinalspecial-purpose methods- Usable in high-performance bitset-based
EnumSetandEnumMapclasses
- Enums are treated by the language specially:
- Enums use a special syntax which simplifies instance creation without writing dozens of
public static finalfields - Enums can be used in
switchstatements - Enums cannot be instantiated outside the enumeration list except by using reflection
- Enums cannot be extended outside the enumeration list
- Enums use a special syntax which simplifies instance creation without writing dozens of
- Java automatically compiles extra stuff into enums:
public static (Enum)[] values();public static (Enum) valueOf(java.lang.String);private static final (Enum)[] $VALUES;(values()returns a clone of this)
Most of these can be emulated with a suitably designed class, but Enum just makes it really easy to create a class with this set of particularly desirable properties.