Java编译错误:打开枚举

编程入门 行业动态 更新时间:2024-10-26 06:26:38
本文介绍了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

  • 打开项目属性
  • 点击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编译错误:打开枚举

    本文发布于:2023-11-25 17:31:21,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:错误   Java

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!