Java编译错误:打开枚举 [英] Java compilation error: switch on enum

查看:117
本文介绍了Java编译错误:打开枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个非常奇怪的错误,我不知道如何解决。

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


  1. 打开项目属性

  2. 点击Java Compiler / li>
  3. 勾选启用项目特定设置

  4. 将所有下拉菜单设置为1.7


  5. 清理项目以触发重建

  1. Open the project properties
  2. Click on "Java Compiler"
  3. Checkmark "Enable project specific settings"
  4. Set all of the drop down menus to 1.7
  5. Hit ok
  6. Clean the project to trigger a rebuild

如果您在下面执行,则问题重新出现

If u do below , then the problem reappears.


  1. 打开项目属性

  2. 点击Java Compiler

  3. 清除启用项目特定设置

  4. 点击OK

  5. 清理项目以触发重建(将重建au

  1. Open the project properties
  2. Click on "Java Compiler"
  3. Clear "Enable project specific settings"
  4. Hit ok
  5. Clean the project to trigger a rebuild (it will rebuild automatically)

以下是我看到的如果我执行以下操作...

Here's what I see if I do the following...


  1. 打开项目属性

  2. 点击Java编译器

  3. 点击配置工作区设置 li>
  4. 我看到编译器合规级别= 1.7

  5. 我看到使用默认合规性设置被选中。

  1. Open the project properties
  2. Click on "Java Compiler"
  3. Click on "Configure Workspace Settings"
  4. I see that the "Compiler compliance level" = 1.7
  5. I see that "Use default compliance settings" is checked.

希望这有帮助!!

这篇关于Java编译错误:打开枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆