Java编译错误:打开枚举 [英] Java compilation error: switch on enum
问题描述
我遇到了一个非常奇怪的错误,我不知道如何解决。
I came across a very weird error that I just can't figure out how to solve.
一个在Windows上编译的项目不会在Linux上编译出以下错误:
A project, that compiles just fine on Windows, doesn't compile on Linux with the following error:
Cannot switch on a value of type AClass.Bbb. Only convertible int values, strings or enum variables are permitted
,即使所陈述的类型是一个枚举。
, even though the stated type is an enum.
类的代码是这样的:
The code of the class is something along these lines:
public class AClass {
private enum Bbb {
ONE,
TWO;
}
public void aMethod(List<Bbb> arg) {
for (Bbb en : arg) {
switch (en) {
....
}
}
}
}
switch(en)
中的 en
下划线,并显示上述错误通知。
The en
in switch(en)
is underlined, with the error notification stated above.
有其他人有吗?有没有办法解决这个问题?
Has anyone else had it? Is there a way to solve this?
UPD Java版本:
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
推荐答案
如果您使用JDK1.7 .Try按照以下步骤查看
The problem should go away if u r using JDK1.7 .Try following the below steps and see
- 打开项目属性
- 点击Java Compiler / li>
- 勾选启用项目特定设置
- 将所有下拉菜单设置为1.7
- 清理项目以触发重建
- Open the project properties
- Click on "Java Compiler"
- Checkmark "Enable project specific settings"
- Set all of the drop down menus to 1.7
- Hit ok
- Clean the project to trigger a rebuild
如果您在下面执行,则问题重新出现
If u do below , then the problem reappears.
- 打开项目属性
- 点击Java Compiler
- 清除启用项目特定设置
- 点击OK
- 清理项目以触发重建(将重建au
- Open the project properties
- Click on "Java Compiler"
- Clear "Enable project specific settings"
- Hit ok
- Clean the project to trigger a rebuild (it will rebuild automatically)
以下是我看到的如果我执行以下操作...
Here's what I see if I do the following...
- 打开项目属性
- 点击Java编译器
- 点击配置工作区设置 li>
- 我看到编译器合规级别= 1.7
- 我看到使用默认合规性设置被选中。
- Open the project properties
- Click on "Java Compiler"
- Click on "Configure Workspace Settings"
- I see that the "Compiler compliance level" = 1.7
- I see that "Use default compliance settings" is checked.
希望这有帮助!!
这篇关于Java编译错误:打开枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!