2

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.

KiriSakow
  • 957
  • 1
  • 12
  • 22

2 Answers2

7

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.

howlger
  • 31,050
  • 11
  • 59
  • 99
-1

Save the file(rebuild if Build Automatically is off) and that warning should go away.

Naman
  • 27,789
  • 26
  • 218
  • 353
jon5477
  • 520
  • 6
  • 17
  • Had already saved, and 'Build automatically' is actually checked, too. The blue warning still won't go away. – KiriSakow Nov 20 '17 at 16:28
  • Is this under the Info or Warning section in Eclipse? If its highlighted in blue then I'm assuming its under Info. I would check compiler settings (either global or project scope) for how Eclipse handles Info/Warnings for Generics. – jon5477 Nov 20 '17 at 16:45