enum is an enumeration type. Technically, an enum is a
final class with static final fields that are instances of the enum. An
enum Foo is always implicitly a subclass of
Enum<Foo>, which means an enum cannot extend another class, but it can still implement interfaces. Due to the generic parameter, different enums can not have a common ancestor other than
Enum and
Object.
An
enum is
Comparable (compared by the order of declaration of the values) and
Serializable (
only the name of the constant is serialized).
It has a fixed set of values. The values are implicitly
public static final and this cannot be overridden. All rules of
static initialization apply to the initialization of constants.
Copies of enumeration items are not created, even during deserialization. This is why Effective Java
recommends using an
enum for a serializable singleton.
Instances store the
name and the
ordinal number of a constant as fields. The
values static method returns a list of all constants, and
valueOf returns a constant by name.
Specs.
Finalization and cloning of enums are prohibited.