簡體   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)

當我編碼時,我不知道為什么

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中打開它時,我沒有得到那個錯誤。

-source 1.5意味着您的代碼將與Java 1.5版兼容,並且不能使用稍后介紹的語言結構。 閱讀http://docs.oracle.com/javase/8/docs/technotes/tools/unix/javac.html以了解更多信息。

實現您想要的簡單方法(能夠在Java 7中添加鑽石運算符)是在項目定制器中更新項目源/二進制版本 - 轉到“ Projects選項卡(Ctrl-1),選擇項目節點,在其中選擇“ Properties上下文菜單並更新“源”選項卡中的“ Source/Binary Format字段。

你錯過了這個:

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

你必須在“<>”中加入“String”

右鍵單擊並選擇“屬性”,然后選擇此圖片並選擇新版本的源

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM