我想將字符串轉換爲枚舉。但是如何?如何匹配並將字符串切換爲枚舉?
class Letter {
A, B, C
}
String letter = "A";
switch (letter) {
case Letter.A: //cannot convert from Letter to String
case Letter.A.toString(): //case expressions must be constant expressions
case Letter.C.name(): //case expressions must be constant expressions
default:
}
http://stackoverflow.com/questions/604424/java-convert-string-to-enum 這是你想要的嗎? –