【发布时间】:2013-01-28 20:35:27
【问题描述】:
我遇到了一个奇怪的问题,我不确定这是编译器问题还是我对带有接口的枚举的理解。我正在使用 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
我以前做过这个(枚举由接口定义的行为),没有任何问题。有什么想法吗?
【问题讨论】:
-
这里编译得很好。您使用的是哪个编译器和 Java 版本?
-
这里也一样,我确实把它扔进了我的日食中......工作正常
-
@JBNizet 嗯,好吧,我在 IntelliJ 和 Java v1.6 中使用编译器(Android 项目最大)。我如何确定它使用的是什么编译器?
-
刚看了,它说它正在使用
javac。