eclipse not inserting “diamond” operator in a java 8 project

后端 未结 6 626
轮回少年
轮回少年 2021-01-03 21:26

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

Map map = new HashMap<>();
         


        
相关标签:
6条回答
  • 2021-01-03 21:53

    I tried the two other solutions mentioned here, but none of them worked for me. What worked for me was Java > Editor > Content Assist > Advanced and checking Java Non-Type Proposals in the upper box.

    On a different installation, this also had to be checked in the lower area, but it worked in both eclipse installations.

    0 讨论(0)
  • 2021-01-03 21:58

    I observed this error when compiling with maven. To solve it, I had to fix my JAVA_HOME environment variable to the right JDK.

    0 讨论(0)
  • 2021-01-03 22:06

    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.

    0 讨论(0)
  • 2021-01-03 22:16

    What worked for me is enabling/checking Java > Editor > Content Assist > Advanced >Java Proposals. (Upper part of the settings page)

    0 讨论(0)
  • 2021-01-03 22:16

    Ok, it seems that different proposals are in different lists of suggestions, I think that diamond operator constructor is in "Java Non-type Proposals", while the one with arguments is in "Java Proposals". When both lists are included in the default suggestion list, the latter option goes first (though you can still press arrows to select the "diamond" one). The only option how to sort it so it was the first in the list (and hence get inserted by [ctrl+space, enter]) for me was disabling the other ones:

    0 讨论(0)
  • 2021-01-03 22:17

    I had the same problem but the solution to set everything to default didn't work for me. What worked for me is Java > Editor > Content Assist > Advanced and unchecking JPA Proposals in the upper window.

    0 讨论(0)
提交回复
热议问题