鉴于此课程:
public class Outer {
public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
}
}
我尝试了new Outer().Day.values();
和new Outer().Day.getEnumConstants();
,但我得到了Day cannot be resolved or is not a field
知道如何访问它吗?
答案 0 :(得分:3)
您可以访问如下:Outer.Day.values();
枚举Day
可以像静态变量一样公开访问。
答案 1 :(得分:1)
我使用IDEONE运行您的代码,这是我的解决方案(根据您的需求调整):
public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
}
public static void main (String[] args) throws java.lang.Exception
{
Day[] d = Outer.Day.values();
for (Day dd : d){
System.out.println(dd);
}
}
链接是 - http://ideone.com/B1qLKg
这就是你想要的吗?