在某些场景下我们需要动态生成一些枚举值,主要是通过反射生成,但是这种生成枚举值是不能switch的
1.枚举值类
public enum CodeInfoEnum {
LOCK(1L, 1L, "LOCK_TYPE", "LOCK"), UNLOCK(1L, 2L, "LOCK_TYPE", "LOCK");
public Long classId;
public Long infoId;
public String classCode;
public String infoCode;
CodeInfoEnum(Long classId, Long infoId, String classCode, String infoCode) {
this.classId = classId;
this.infoId = infoId;
this.classCode = classCode;
this.infoCode = infoCode;
}
public static CodeInfoEnum getByInfoId(Long infoId) {
return CodeInfoEnum.valueOf(infoId + "");
}
public static List getByClassId(Long classId) {
return Arrays.stream(CodeInfoEnum.values()).filter(item -> item.classId.equals(classId)).collect(Collectors.toList());
最后
以上就是单薄星星最近收集整理的关于java 动态 枚举_java 动态生成枚举值的全部内容,更多相关java内容请搜索靠谱客的其他文章。
发表评论 取消回复