使用枚举切换语句在Java中不起作用

Cod*_*per 2 java enums switch-statement

我创建了一个这样的枚举

public enum Direction {
    NORTH, SOUTH, WEST, EAST, NORTHWEST, NORTHEAST, SOUTHWEST, SOUTHEAST
}
Run Code Online (Sandbox Code Playgroud)

然后我尝试在switch语句中使用它

 Direction direction = Direction.NORTH;
    switch(direction){
    NORTH:
        System.out.println("Syntax error on token {, case expected after this token");
        break;
    }
Run Code Online (Sandbox Code Playgroud)

我收到了我在println中输入的错误...

ric*_*din 5

你错过了case关键字.

switch(direction){
case NORTH:
    System.out.println("Syntax error on token {, case expected after this token");
    break;
}
Run Code Online (Sandbox Code Playgroud)

演示