如何循环枚举类型

如下代码:

public enum CardType {

    UNKNOW(0, "未知"),
    DEBIT_CARD(1, "借记卡"),
    CREDIT_CARD(2, "信用卡");

    private final byte value;

    private final String desc;

    private CardType(int value, String desc) {
        this.value = (byte) value;
        this.desc = desc;
    }
    //循环枚举的静态方法
    public static boolean ifInElements(int num){
        for (CardType ele : CardType.values()) {
            if(num==ele.getValue())
                return true;
        }
        return false;
    }

    public byte getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    @Override
    public String toString() {
        return String.valueOf(this.getValue());
    }
}

 

posted @ 2018-03-27 10:31  如果屈原会编程  阅读(674)  评论(0编辑  收藏  举报