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中输入的错误...
你错过了case关键字.
switch(direction){
case NORTH:
System.out.println("Syntax error on token {, case expected after this token");
break;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
611 次 |
| 最近记录: |