Java uses enum to define the type of constants, and constants themselves have type information, which can be compared by = =. The type defined by enum is class, and all constants inherited from java.lang.Enum are unique reference instances, and constants can be used in switch statements.
Name () gets the string defined by the constant. Be careful not to use toString (). Ordinal () returns the order of constant definitions (meaningless). Constructors, fields and methods can be written for enumeration classes, and constructors must be private.
After the new data type definition is completed, it can be used. We have seen the most basic data types, such as integer int, single-precision floating point float, double-precision floating point double, char, short integer short and so on.
An enumeration is a collection, and the elements (enumeration members) in the collection are named integer constants, and the elements are separated by commas.
DAY is an identifier, which can be regarded as the name of this collection. It is optional, that is, a dispensable item.
The default value of the first enumerated member is the integer 0, and the sum of the values of the subsequent enumerated members and the values of the previous member is 1.
You can set the values of enumeration members artificially to customize an integer range.
Enumeration is an alternative to preprocessing instruction #define.