Java: using switch statement with enum under subclass
Change it to this:
switch (enumExample) {
case VALUE_A: {
//..
break;
}
}
The clue is in the error. You don't need to qualify case
labels with the enum type, just its value.
Java infers automatically the type of the elements in case
, so the labels must be unqualified.
int i;
switch(i) {
case 5: // <- integer is expected
}
MyEnum e;
switch (e) {
case VALUE_A: // <- an element of the enumeration is expected
}
Wrong:
case AnotherClass.MyEnum.VALUE_A
Right:
case VALUE_A: