Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eclipse not inserting "diamond" operator in a java 8 project

I have a maven project configured to use Java 8 and all works fine, eclipse compiles code like:

Map<String,String> map = new HashMap<>(); 

It even complains about old-style code ("redundant specification of type arguments") when I set this on the Error/Warnings tab. The problem is, I can't work out how to make it use this syntax by default on autocompletion - I'm pretty sure I saw it working earlier but now whenever I ctrl-space to insert a constructor, it insists on adding the parameters, which I don't like.

Can anybody hint what setting to check to make content assist insert <> instead of < String,String >? Or perhaps it's related to the fact I'm using Java 8 not Java 7, or that I'm on maven?

like image 569
Lili Avatar asked Jul 19 '14 14:07

Lili


People also ask

Which Java version is diamond operator?

Diamond Operator: Diamond operator was introduced in Java 7 as a new feature. The main purpose of the diamond operator is to simplify the use of generics when creating an object.

Where is Diamond in Java?

Diamonds now spawn from Y level 14 all the way down to Y level -63. This is the range players should be in if they expect to find diamonds. However, the most specific level is now Y level -59. This level, and the ones immediately above and below, house the best chance of finding diamonds when strip mining.

What is Diamond interface in Java?

The diamond operator – introduced in Java 1.7 – adds type inference and reduces the verbosity in the assignments – when using generics: List<String> cars = new ArrayList<>(); The Java 1.7 compiler's type inference feature determines the most suitable constructor declaration that matches the invocation.


1 Answers

I had this issue just a few minutes ago and solved it half way through typing out an SO question.

Eclipse's auto-complete apparently prioritized the old-style generic syntax after I had fiddled with the advanced content assist settings a while ago. Try resetting Java > Editor > Content Assist > Advanced to defaults; this was what fixed it for me and returned auto-complete to inserting the diamond syntax by default.

like image 98
Marco van Hilst Avatar answered Sep 18 '22 10:09

Marco van Hilst