【发布时间】:2014-10-04 09:21:36
【问题描述】:
我有枚举,例如:
public enum Type {
Type1(10),
Type2(25),
Type3(110);
private final int value;
Type(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
我想在 switch 中使用枚举:
switch (indexSector) {
case Type.Type2.getValue():
//...
break;
}
但 IDE 说“需要常量表达式”。如何在 switch 中使用 Enum 这种类型?
【问题讨论】:
标签: java android enums switch-statement