java 枚举 找不到符号
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 枚举 找不到符号相关的知识,希望对你有一定的参考价值。
public class EnumWithMethods
public enum Season
SPRING,SUMMER,FALL,WINTER;
private final static String location="Phoenix";
public static Season getBest()
if(location.equals("Phoenix"))
return WINTER;
else
return SUMMER;
public static void main(String args[])
System.out.println(Season.getBest());
书上的程序,显示了3个错误,都是找不到符号,分别是WINTER,SUMMER,getBest方法,麻烦高手解释下
public enum Season
SPRING, SUMMER, FALL, WINTER
;
private final static String location = "Phoenix";
public static Season getBest()
if (location.equals("Phoenix"))
return Season.WINTER;//
else
return Season.SUMMER;//
public static void main(String args[])
System.out.println(EnumWithMethods.getBest());//
说明:1、WINTER、SUMMER是Season中定义的要改为:Season.WINTER、Season.SUMMER;
2、getBest()函数定义为public static 类型的,你在本类(EnumWithMethods而非Season)中可直接调用写成System.out.println(getBest());,或加上类名的System.out.println(EnumWithMethods.getBest()); 参考技术A public class EnumWithMethods
public enum Season
SPRING,SUMMER,FALL,WINTER;
private final static String location="Phoenix";
public static Season getBest()
if(location.equals("Phoenix"))
return Season.WINTER;
else
return Season.SUMMER;
public static void main(String args[])
System.out.println(getBest());
参考技术B public enum Season
SPRING,SUMMER,FALL,WINTER;
多了一个;号。把那个去掉。
以上是关于java 枚举 找不到符号的主要内容,如果未能解决你的问题,请参考以下文章