代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
public enum StateEnum { //添加枚举的指定常量 online(10), offline(20); //必须增加一个构造函数,变量,得到该变量的值 private int mState=0; private StateEnum(int value) { mState=value; } /** * @return 枚举变量实际返回值 */ public int getState() { return mState; } } |
1 2 3 4 5 6 |
//enum StateEnum orderState=StateEnum.offline; //orderState=StateEnum.online; System.out.println("state="+ orderState.getState()); //output state=20 |