Data collated in the network: reference http://blog.csdn.net/column/details/java0115.html, thank you here
1. About the use of enumerations
The enum enum type in Java has many unexpected uses, so let's take a look at it here. 1, you can add variables and methods in the enum
Let's take a look at some code examples:[Java] View plain copy public enum state { normal ("normal", 1), update ("updated", 2), deleted ("deleted", 3), fired ("masked", 4 ); // member variables private String name; private int index; // Construction method, note: The construction method cannot be public because an enum cannot be instantiated private state (string name, int index) { this.name = name; this.index = index; } // General methods public static string getname (Int index) { for (state c : state .values ()) { if (C.getindex () == index) { return c.name; } } return null;    } get set Method public string getname () { return name; } public void setname (String name) { this.name = name; } public int getindex () { return index; } &NBsp; public void setindex (Int index) { this.index = index; } }
From the above code we can see that the enumeration values are defined, followed by a semicolon, and then other variables and methods can be defined. In addition, it is necessary to note that the constructor method in the enum cannot be identified by public, in order to prevent the user from instantiating the enum. 2, can be used to define constants
Let's review how to define constants in Java, and look at the following code:
public static final int normalstate = 1;
private static final int updatestate = 2;
We can also use the Enum enumeration to replace the above constant definition, the following code: [Java] view plain copy