The enumeration definition

An enum type is a legal type composed of a fixed set of constants, provided in java1.5. In Java, the keyword enum defines an enumerated type.

public enum Week {
    MON, TUE, WED, THUR,FRI,SAT,SUN;
}
Copy the code
  • This parameter is modified with keyword enum
  • Can be embedded in other Java classes
  • Enumerations can implement one or more joins
  • New methods can be defined

Enumeration implementation

Public Final Class Week extends Enum. This class extends Enum. The final keyword tells us that this class cannot be inherited.

Enumerations are the best way to implement singletons. Enumerations solve thread-safety problems and solve the problem of deserialization breaking singletons, see the link below.

Hollischuang. Gitee. IO/tobetopjava…