NetBeans:-source 1.5不支持菱形运算符(使用-source 7或更高版本启用菱形运算符)
我在编码时不知道为什么:
I don't know why when I code:
List<String> data = new ArrayList<>();
它说
diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
----
(Alt-Enter shows hints)
我已经使用了JDK 1.7。当我在eclipse中打开它时,我没有得到那个错误。
I already use JDK 1.7. When I opened it in eclipse, I didn't get that error.
-source 1.5
表示您的代码将与Java 1.5版兼容,并且不能使用稍后介绍的语言结构。阅读 http://docs.oracle.com/javase/8/docs/technotes /tools/unix/javac.html 以查找更多信息。
-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.html to find more.
轻松实现您想要的方式(能够在Java 7中添加钻石运算符) )是在项目定制器中更新项目源/二进制版本 - 转到项目
选项卡(Ctrl-1),选择项目节点,选择属性
在其上下文菜单中,并在源选项卡中更新源/二进制格式
字段。
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.