我遇到了一个奇怪的问题,我不确定是编译器问题还是我对枚举接口的理解。我正在使用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我以前也这样做过(使用接口定义的行为进行枚举),没有任何问题。有什么想法吗?
发布于 2013-01-29 04:45:49
您可以尝试以下替代方法:
public enum MyEnum implements Action {
ACTIONABLE(true),
NOT_ACTIONABLE(false);
private final boolean actionable;
MyEnum(boolean actionable) {
this.actionable = actionable;
}
@Override
public boolean isActionable() {
return this.actionable;
}
}https://stackoverflow.com/questions/14570746
复制相似问题