I. Analysis in general, the enumeration item that we often use has only one attribute, that is, the sorting number. Its default value is from 0, 1, 2 ....... However, in addition to the sorting number, the enumeration has one or more attributes. II. For example, you can declare the business value by enumerative constructors, define the optional values, and add attributes. See the following code:
Enum Role {Admin ("Administrator", new Lifetime (), new Scope (); User ("common User", new Lifetime (), new Scope ()); // Chinese description private String name; // Role life cycle private Lifetime lifeTime; // permission range private Scope scope; Role (String _ name, Lifetime _ lt, Scope _ scope) {name = _ name; lifeTime = _ lifeTime; scope = _ scope;}/** name, lifeTime, and scope get methods are relatively simple and will not be repeated */}
You can read a book, so that developers can have a three-dimensional and Multidimensional Awareness of the Admin and User constants, including names, lifecycles, and scopes, you can also easily obtain such attributes in the program. 3. We recommend that you define the description for each enumeration in the enumeration definition, especially in large-scale project development, A large number of constant item definitions use enumeration item descriptions more user-friendly and concise than adding annotations to an interface constant or class constant.