我似乎无法像从内部类内部那样从枚举内部访问周围类的实例成员。这是否意味着枚举是静态的?是否可以访问周围类的实例的范围,还是必须在需要的地方将实例传递给枚举的方法?public class Universe { public final int theAnswer; public enum Planet { // ... EARTH(...); // ... // ... constructor etc. public int deepThought() { // -> "No enclosing instance of type 'Universe' is accessible in this scope" return Universe.this.theAnswer; } } public Universe(int locallyUniversalAnswer) { this.theAnswer = locallyUniversalAnswer; }}
添加回答
举报
0/150
提交
取消