作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是一名Java自学者,被这个问题困扰了。尝试过不合理的组合和可能的解决方案,但遇到了更多的错误。
public class SeasonsSwitch {
enum Season {
WINTER,
SPRING,
SUMMER,
FALL
}
public static void main(String[] args){
String currentSeason;
currentSeason = TextIO.getWord();
switch (currentSeason){
case WINTER:
TextIO.put("Decemeber, January, February");
break;
case SPRING:
TextIO.put("March, April, May");
break;
case SUMMER:
TextIO.put("June, July, August");
break;
case FALL:
TextIO.put("September, October, November");
}
}
}
error. cannot find symbol
case WINTER
error. cannot find symbol
case SPRING
error. cannot find symbol
case SUMMER
error. cannot find symbol
case FALL
最佳答案
使用Season.valueOf
将枚举常量的字符串表示形式转换为枚举常量。
Season s = Season.valueOf(currentSeason);
switch (s){
The java.lang.Enum.valueOf() method returns the enum constant of the specified enumtype with the specified name. The name must match exactly an identifier used to declare an enum constant in this type.
关于java - 枚举和开关帮助。 Java学习者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25898214/
我是一名优秀的程序员,十分优秀!