在Java中使用用于switch case的枚举

Sam*_*rma -2 java enums spring java-ee

我正在实现一个简单的开关盒,它将打开一个Enum值.以下是代码

ScheduleType scheduleType = ScheduleType.valueOf(scheduleTypeString);

switch (scheduleType) {

       case ScheduleType.CRON_EXPRESSION: 
                    System.out.println("Cron");
                    break;
}
Run Code Online (Sandbox Code Playgroud)

但我在IDE中收到以下错误:

The qualified case label ScheduleType.CRON_EXPRESSION must be replaced with the unqualified enum constant CRON_EXPRESSION
Run Code Online (Sandbox Code Playgroud)

有人可以解释为什么我会得到这个错误以及代码有什么问题.我知道正确的方法是删除ClassName,但为什么我需要这样做呢?因为通常在比较中我确实使用它,例如在equals和all中.谢谢

Mik*_*e B 6

不要上课名.case ScheduleType.CRON_EXPRESSION:应该是case CRON_EXPRESSION:.

或者换句话说,必须用非限定枚举常量CRON_EXPRESSION替换ScheduleType.CRON_EXPRESSION.