Java NetBeans:-source 1.5 不支持菱形运算符(使用 -source 7 或更高版本启用菱形运算符)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22943123/
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-13 19:29:05  来源:igfitidea点击:

NetBeans : diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator)

javanetbeans

提问by vuhoanghiep1993

I don't know why when I code:

我不知道为什么当我编码时:

List<String> data = new ArrayList<>();

it said that

它说

diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)
----
(Alt-Enter shows hints)

I already use JDK 1.7. When I opened it in eclipse, I didn't get that error.

我已经在使用 JDK 1.7。当我在 eclipse 中打开它时,我没有收到那个错误。

采纳答案by Radim

-source 1.5means your code will be compatible with Java version 1.5 and cannot use language constructs introduced later. Read http://docs.oracle.com/javase/8/docs/technotes/tools/unix/javac.htmlto find more.

-source 1.5意味着您的代码将与 Java 1.5 版兼容,并且不能使用稍后引入的语言结构。阅读http://docs.oracle.com/javase/8/docs/technotes/tools/unix/javac.html以了解更多信息。

Easy way to achieve what you want (to be able to use diamond operator added in Java 7) is to update project source/binary version in project customizer - go to Projectstab (Ctrl-1), select project node, choose Propertiesin its context menu and update Source/Binary Formatfield in Source tab.

实现您想要的(能够使用 Java 7 中添加的菱形运算符)的简单方法是在项目定制器中更新项目源/二进制版本 - 转到Projects选项卡 (Ctrl-1),选择项目节点,Properties在其上下文菜单中选择并更新Source/Binary Format源选项卡中的字段。

回答by Ale

You missed this:

你错过了这个:

List<String> data = new ArrayList<String>();

List< String> data = new ArrayList< String>();

You have to put "String" in both "<>"

你必须在两个“<>”中都加上“String”

回答by Ruthe

right click and choose Properties follow this picture and select new version of source

右键单击并选择属性按照此图片并选择新版本的源