Reputation: 3843
LocalDate currentdate = LocalDate.now();
Month currentMonth = currentdate.getMonth();
FrequencyEntity frequencyEntity = null;
switch (currentMonth) {
case Month.JANUARY: // Here.
frequencyEntity = FrequencyEntity.builder().january(frequency).build();
}
The line I have commented as "Here" causes my IDE to show this: "An enum switch case label must be the unqualified name of an enumeration constant.".
The only possible solution I can envisage is convert the month to String. But this may be not a correct solution.
Is there a more elegant way?
Upvotes: 0
Views: 161
Reputation: 1502316
Note the unqualified part in the error message. It's not saying you can't use enum values as case labels - it's saying that you can't include the enum name. The code should be:
switch (currentMonth) {
case JANUARY:
frequencyEntity = FrequencyEntity.builder().january(frequency).build();
break;
}
Upvotes: 4