public enum SexEnum { Man(0, "man"), Woman(1, "woman"); private String desc; private int value; SexEnum(int value, String desc) { this.value = value; this.desc = desc; } public int value() { return this.value;//this 当前的对象(有点类似反射?) } public String desc() { return this.desc; } public static SexEnum getEnum(int index) { for (SexEnum se : SexEnum.values()) { if (se.value == index) { return se; } } return null; } public static SexEnum getEnum(String desc) { for (SexEnum se : SexEnum.values()) { if (se.desc().equals(desc)) { return se; } } return null; } }
枚举
最新推荐文章于 2024-03-24 12:41:50 发布