/**
* Use of Java enumerations
* @author RSun
* @Date 2012-11-7 11:46:08
*/
public class Enumtest {
public static void Main (string[] args) {
System.out.println ("Using enumerations:" + T.AA);
SYSTEM.OUT.PRINTLN ("Use enumeration ID:" + t.aa.getid ());
SYSTEM.OUT.PRINTLN ("Use enumeration value:" + t.aa.getvalue ());
System.out.println ("Get enumeration property by name:" + t.valueof ("AA"). GetId ());
}
public enum t{
AA (1, "a"), BB (2, "B"), CC (3, "C");
private int id;
private String value;
T () {};
T (int ID, String value) {
This.id = ID;
This.value = value;
}
Get and set
public int getId () {
return ID;
}
public void setId (int id) {
This.id = ID;
}
Public String GetValue () {
return value;
}
public void SetValue (String value) {
This.value = value;
}
}
}
JAVA7 The previous switch does not support string types, but we can do this through enumerations, see Enum enumeration combined with the use of switch