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
NetBeans : diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator)
提问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.5
means 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 Projects
tab (Ctrl-1), select project node, choose Properties
in its context menu and update Source/Binary Format
field 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”