“意外类型”比较枚举值时出错
我见过的大多数遇到此问题的人都在需要 ==
的地方使用 =
。是什么导致了我这里的问题?
com\callmeyer\jopp\FieldCoordinator.java:303: unexpected type required: class, package found : variable if (event.getType() == event.Type.INSERT) { ^
枚举定义和访问器:
public class DataLayoutEvent {
public static enum Type { INSERT, DELETE, RENAME, MOVE, RESIZE }
private Type type = null;
public Type getType() {
return type;
}
...
}
以及发生错误的方法:
public void layoutChanged(DataLayoutEvent event) {
if (event.getType() == event.Type.INSERT) {
fieldAdded(event.getField(), event.getToIndex());
}
...
Most people I've seen with this problem were using =
where they needed ==
. What's causing my problem here?
com\callmeyer\jopp\FieldCoordinator.java:303: unexpected type required: class, package found : variable if (event.getType() == event.Type.INSERT) { ^
The enum definition and accessor:
public class DataLayoutEvent {
public static enum Type { INSERT, DELETE, RENAME, MOVE, RESIZE }
private Type type = null;
public Type getType() {
return type;
}
...
}
and the method where the error occurs:
public void layoutChanged(DataLayoutEvent event) {
if (event.getType() == event.Type.INSERT) {
fieldAdded(event.getField(), event.getToIndex());
}
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
使用静态访问而不是实例访问:
您可以(但不应该)对静态成员(方法和字段)使用实例访问,但不能对内部类型使用实例访问。
Use static access instead of instance access:
You can (but shouldn't) use instance access for static members (methods and fields), but not for inner types.