Eclipse warning "Replace the type specification in this constructor call with the diamond operator ('<>')" in a Java project

KiriSakow picture KiriSakow · Nov 20, 2017 · Viewed 11.6k times · Source

What does Eclipse mean when it asks to Replace the type specification in this constructor call with the diamond operator ('<>'), since the said operator is already there?

Then I put the cursor on what is underlined in blue, and press F2 to learn more, and I get this message (Replace the type specification in this constructor call with the diamond operator ('<>')):

An Eclipse warning saying "Replace the type specification in this constructor call with the diamond operator ('<>')"

And if I delete Object from within <>, Eclipse still is not happy:

An Eclipse warning saying "Replace the type specification in this constructor call with the diamond operator ('<>')"

EDIT

We made sure that

  • java.util.List was imported
  • changes were saved
  • Project -> Clean... command was applied

The blue warning still won't go away.

Answer

howlger picture howlger · Nov 20, 2017

This seems to be a bug in the SonarLint's diamond operator checker, not of Eclipse JDT: see the source code of SonarLint that contains the message.

See also: SonarJava Rule 2293: The diamond operator ("<>") should be used

Solution:

Disable the SonarJava rule 2293 and use the Eclipse warning Generic types > Redundant type argument (1.7 or higher) instead.