public enum XEnum { GENERATE(0), USE(1), STOP(2); private int value = 0; XfaqEwmSfyxEnum(int value){ this.value = value; } public int value(){ return this.value; } }
枚举时通常添加一个int值,或者添加一个键值对 整数与字符串对应,如下:
public enum AdminTypeEnum { SYSTEM("系统管理员",1), AGENT("商会管理员",2); private final int val; private final String desc; private AdminTypeEnum(String desc,int val) { this.val = val; this.desc = desc; } public static AdminTypeEnum getEnumType (int val) { for (AdminTypeEnum type : AdminTypeEnum.values()) { if (type.getVal() == val) { return type; } } return null; } public int getVal() { return val; } public String getDesc() { return desc; } }