Java eclipse中的openjdk 1.7:低于1.7的源代码级别不允许使用运算符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19382370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 16:38:15  来源:igfitidea点击:

openjdk 1.7 in eclipse: operator is not allowed for source level below 1.7

javaeclipsewindows-runtimeopenjdk

提问by dorien

Eclipse gives me an error:

Eclipse 给了我一个错误:

'<>' operator is not allowed for source level below 1.7 

I guess this is because it is not using java 1.7. Except that it is. At least openjdk 1.7 (my OS is OpenSuse 12.3).

我想这是因为它没有使用 java 1.7。除了它是。至少是 openjdk 1.7(我的操作系统是 OpenSuse 12.3)。

I switched back from kepler to juno to reduce some lags and try to figure out this bug as well, to no avail so far.

我从开普勒切换回朱诺以减少一些滞后并尝试找出这个错误,到目前为止无济于事。

Some things I have tried: - the default runtime for eclipse is opensdk 1.7 (says so in help, about, installation details) - project properties, java build -> library. I have manually added the opensdk location.

我尝试过的一些事情: - eclipse 的默认运行时是 opensdk 1.7(在帮助、关于、安装细节中是这样说的) - 项目属性、java 构建 -> 库。我已经手动添加了 opensdk 位置。

I would install the oracle version, but there is only 1.6 available from the opensuse repository. I already tried installing the rpm offered by oracle, that didn't put itself in my path and kind of messed everything up, so I removed that again.

我会安装 oracle 版本,但 opensuse 存储库中只有 1.6 可用。我已经尝试安装 oracle 提供的 rpm,它没有把自己放在我的路径中并且把一切都搞砸了,所以我再次删除了它。

It should work with openjdk as well no? Or do you think it has a bug?

它也应该与 openjdk 一起使用,不是吗?或者你认为它有一个错误?

ps: junit also was not recognised, so I manually linked to the jar file. Perhaps this is relevant information.

ps:junit也无法识别,所以我手动链接到jar文件。也许这是相关信息。

采纳答案by Eric Jablow

In your project's preferences, you must set the compiler --sourceoption to 1.7and --targetoption to 1.7also. There are dedicated option boxes for that.

在项目的喜好,你必须设置编译器--source选项1.7--target选项1.7也。有专门的选项框。

Right-click on the project. Choose Properties. Choose Java Compileron the left. Choose 1.7for the Compiler Compliance level. If the 2 drop-downs below that aren't 1.7, uncheck Use default compliance settingsand set those to 1.7.

右键单击项目。选择属性。选择左侧的Java Compiler。选择1.7编译器的级别。如果下面的 2 个下拉菜单不是1.7,请取消选中使用默认合规性设置并将其设置为1.7

回答by ang

right click on the error, choose quick fix, and select change JRE to 1.7

右键单击错误,选择快速修复,然后选择将 JRE 更改为 1.7

回答by DilanG

If you want to use below version, use

如果要使用以下版本,请使用

Map<String, Integer> map = new HashMap<String, Integer>();

instead of

代替

HashMap<String, Integer> map = new HashMap<>();

回答by David B.

If you would like to stick with java 1.6, Search and replace <> with empty string. You'll get compiler warnings but the errors should go away.

如果你想坚持使用java 1.6,搜索并用空字符串替换 <>。您会收到编译器警告,但错误应该会消失。

回答by Eduard

I had the same problem, but with the - Compiler Compliance Level - Generated .class files compatibility - Source compatibility all already set to 1.7. I reselected 1.7 on all 3 and then Eclipse detected it, asked to rebuild and built my project successfully.

我遇到了同样的问题,但是 - 编译器合规性级别 - 生成的 .class 文件兼容性 - 源兼容性都已设置为 1.7。我在所有 3 个上重新选择了 1.7,然后 Eclipse 检测到它,要求重建并成功构建我的项目。

回答by Pete B.

Window->Preferences->Java->Compiler

窗口->首选项->Java->编译器

select 1.7 and hit okay.

选择 1.7 并点击 OK。

If you are building automatically, it will require a full re-build.

如果您是自动构建,则需要完全重新构建。

回答by rajlaxmi_jagdale

Right-click on the project. Choose Properties. Choose Java Compiler on the left. Choose 1.7 for the Compiler Compliance level. If the 2 drop-downs below that aren't 1.7, uncheck Use default compliance settings and set those to 1.7.

右键单击项目。选择属性。选择左侧的 Java Compiler。为编译器合规性级别选择 1.7。如果下面的 2 个下拉菜单不是 1.7,请取消选中使用默认合规性设置并将其设置为 1.7。

回答by Fred Donghwan Kim

right click on Project - properties - Java Complier - Compiler compliance -set level 1.7

右键单击项目 - 属性 - Java 编译器 - 编译器合规性 - 设置级别 1.7