java中使用枚举类型,代码如下

public enum CommonStatus {
    NORMAL(1), PAUSE(2), DELETE(3);
    private int value;
    private CommonStatus(int v) {
        this.value = v;
    }
    
    public int getValue() {
        return value;
    }
    
    public static String getName(int v) {
        switch (v) {
        case 1:
            return "正常";
        case 2:
            return "停用";
        case 3:
            return "删除";
        default:
            return "";
        }
    }
    
    public static String getName(CommonStatus s) {
        return getName(s.getValue());
    }
}

posted @ 2016-09-26 18:30  包远志  阅读(1441)  评论(0编辑  收藏  举报