简体   繁体   English

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

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

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. 我已经使用JDK 1.7了。 When I opened it in eclipse, I didn't get that error. 当我在eclipse中打开它时,我没有得到那个错误。

-source 1.5 means your code will be compatible with Java version 1.5 and cannot use language constructs introduced later. -source 1.5意味着您的代码将与Java 1.5版兼容,并且不能使用稍后介绍的语言结构。 Read http://docs.oracle.com/javase/8/docs/technotes/tools/unix/javac.html to find more. 阅读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字段。

You missed this: 你错过了这个:

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

You have to put "String" in both "<>" 你必须在“<>”中加入“String”

右键单击并选择“属性”,然后选择此图片并选择新版本的源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:(24,46)错误:-source 1.6不支持Diamond运算符(使用-source 7或更高版本来启用Diamond运算符) - Error:(24, 46) error: diamond operator is not supported in -source 1.6 (use -source 7 or higher to enable diamond operator) -source 1.5 不支持菱形运算符 - diamond operator is not supported in -source 1.5 HEROKU使用-source 7或更高版本来启用钻石操作员 - HEROKU use -source 7 or higher to enable diamond operator Ant使用-source 7或更高版本来启用钻石操作员 - Ant use -source 7 or higher to enable diamond operator 错误:-source1.5不支持菱形运算符 - error: diamond operator is not supported in -source1.5 Apache Maven:-source 1.5中不支持Diamond运算符 - Apache Maven: Diamond operator is not supported in -source 1.5 Maven编译错误:(使用-source 7或更高版本启用菱形运算符) - Maven Compilation Error: (use -source 7 or higher to enable diamond operator) 为什么我得到错误 diamond operator is not supported in -source 1.5 in Java? - Why i get error diamond operator is not supported in -source 1.5 in Java? Visual Studio 2012 + Ant:-source 1.5中不支持Diamond运算符 - Visual Studio 2012 + Ant: diamond operator is not supported in -source 1.5 源1.6不支持Java Combo Box Diamond运算符 - Java Combo Box Diamond Operator not supported in source 1.6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM