我遇到了一个奇怪的问题,我不确定这是编译器问题还是我对带有接口的枚举的理解。我正在使用 IntelliJ IDEA 12,构建一个 Android 项目,并且我有一个这样的类:
public class ClassWithEnum {
private MyEnum myEnum;
//Trying to access it internally here throws the error
public boolean isActionable() {
return myEnum.isActionable();
}
public enum MyEnum implements Action {
ACTIONABLE() {
@Override
public boolean isActionable() { return true; }
},
NOT_ACTIONABLE() {
@Override
public boolean isActionable() { return false; }
}
}
public interface Action {
public boolean isActionable();
}
}
现在,这最初是有效的,但现在编译器抱怨(我已经在一个全新的项目中尝试过,结果相同)并出现错误:
java: /Users/kcoppock/Documents/Projects/EnumInterfaceTest/src/com/example/EnumInterfaceTest/ClassWithEnum.java:11: cannot find symbol
symbol : method isActionable()
location: class com.example.EnumInterfaceTest.ClassWithEnum.MyEnum
我以前做过这个(由接口定义的行为的枚举)没有问题。有什么想法吗?