The enum constant . reference cannot be qualified in a case label

That's a very strange error, since the solution is quiet simple : juste remove the enum class name!

As an example :

public enum DAYS {
MONDAY,
THURSDAT,
WEDNESDAT,
...;
}

When you want to use this enum as a switcher case values, like this :

switch (myValue) {
case DAYS.MONDAY :
break;
....
}
you got this error :

The enum constant DAYS.MONDAY reference cannot be qualified in a case label

Seems weird, but just remvoe "DAYS" and move on.

1 comments:

Kamal said...


This is enforced to avoid people using multiple enums in one switch statement. If MONTHS also is an enum, below will be an incorrect switch statement for sure.

e.g.:
DAYS myValue = ...;
switch (myValue) {
case DAYS.MONDAY :
break;
case MONTHS.JANUARY :
break;
}

I also discussed this here



Post a Comment