Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

java - 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. When I opened it in eclipse, I didn't get that error.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

-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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...