系统做对接,2个系统字典不一致,有时候还有些脏数据,转换时容易出错,有没有办法在遇到脏速度的情况下使用default
/**
* 常住类型
*/
public enum Household {
household_01(1, "户籍"),
household_02(2, "非户籍");
private int index;
private String name;
Household(int index, String name) {
this.index = index;
this.name = name;
}
public int getIndex() {
return index;
}
public String getName() {
return name;
}
private static final Map<Integer, Household> lookup_int = new HashMap<>();
static {
for (Household e : EnumSet.allOf(Household.class)) {
lookup_int.put(e.getIndex(), e);
}
}
public static Household find(int index) {
Household value = lookup_int.get(index);
if (value == null) {
return null;
}
return value;
}
}
https://bbs.csdn.net/topics/392183589
枚举类型有自己的集合访问方法,建议使用如下方式
/**
* 常住类型
*/
public enum Household {
household_01(1, "户籍"),
household_02(2, "非户籍");
private int index;
private String name;
Household(int index, String name) {
this.index = index;
this.name = name;
}
public int getIndex() {
return index;
}
public String getName() {
return name;
}
public static Household find(int index) {
for(Household value:values()){
if ((value.getIndex() == index)) {
return value;
}
}
// 匹配不到则返回一个默认值
return household_01;
}
}