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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With