【发布时间】:2020-12-10 03:10:21
【问题描述】:
我有以下enum,其中包含两个值,一个字符串标识符和一个布尔有效状态。我希望能够通过使用字符串标识符来获取状态值。
有没有人有什么建议可以添加到下面的代码中?
public enum MyEnum {
TYPEA("001", true),
TYPEB("002", false);
private final String identifier;
private final boolean valid;
MyEnum(String identifier, boolean valid) {
this.identifier = identifier;
this.valid = valid;
}
}
【问题讨论】:
-
这能回答你的问题吗? How to get the enum type by its attribute?
-
不,我正在尝试通过另一个枚举值获取一个枚举值。