假设我有这个枚举:
public enum MyEnum {
AUSTRALIA_SYDNEY ("Australia/Sydney"),
AUSTRALIA_ADELAIDE ("Australia/Adelaide"),
private String name
private Timezone(String name){
this.name = name
}
public String value() {
name
}
String toString() {
name
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法让我使用其值/名称获取枚举?现在,我正在尝试这样做,但它不起作用:
MyEnum.valueOf("Australia/Sydney")
Run Code Online (Sandbox Code Playgroud)
What I'm getting from the DB is a string (in this case: "Australia/Sydney"), and not the value, and unfortunately, I can't just alter the type it returns because its an old system and I'm just connecting to this DB that is shared by multiple apps. Anyway around …