如何循环枚举类型

如下代码:

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());
    }
}
原文地址:https://www.cnblogs.com/lxcmyf/p/8656115.html