@Getter
@AllArgsConstructor
public enum NeedTypeEnum {
BIZ("业务需求", 1),
PRODUCT("产品需求", 2),
DESIGN("设计需求", 3),
TECHNOLOGY("技术需求", 4),
OTHER("其他需求", 5);
private final String name;
private final int value;
public static NeedTypeEnum find(int val) {
for (NeedTypeEnum needTypeEnum : NeedTypeEnum.values()) {
if (val == needTypeEnum.getValue()) {
return needTypeEnum;
}
}
return null;
}
}
执行输出结果
- System.out.println(NeedTypeEnum.BIZ);
- System.out.println(SyNeedTypeEnum.BIZ.name());
- System.out.println(SyNeedTypeEnum.BIZ.getName());
- 业务需求(一定情况下会返回"BIZ",而不是"业务需求")
- System.out.println(SyNeedTypeEnum.BIZ.getValue());
@Getter
@AllArgsConstructor
public enum NeedTypeEnum {
BIZ("业务需求", 1),
PRODUCT("产品需求", 2),
DESIGN("设计需求", 3),
TECHNOLOGY("技术需求", 4),
OTHER("其他需求", 5);
private final String title;
private final int value;
public static NeedTypeEnum find(int val) {
for (NeedTypeEnum needTypeEnum : NeedTypeEnum.values()) {
if (val == needTypeEnum.getValue()) {
return needTypeEnum;
}
}
return null;
}
}
执行输出结果
- System.out.println(NeedTypeEnum.BIZ);
- System.out.println(SyNeedTypeEnum.BIZ.name());
- System.out.println(SyNeedTypeEnum.BIZ.getTitle());
- System.out.println(SyNeedTypeEnum.BIZ.getValue());