假如有一个未知类型,枚举可以走default判断吗?

何时丢掉菜鸟称号 2017-06-22 05:29:39
系统做对接,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;
}
}
...全文
272 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
没好心人解答吗

51,399

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧