dfsg76
dfsg76

Reputation: 524

Why doesn't eclipse use the diamond operator in a method parameter

I have a class like this:

public class TestObject
{
   List<String> data;

   public List<String> getData()
   {
     return data;
   }

   public void setData(List<String> inputData)
   {
      data = inputData;
   }
}

I checked the option in Preferences -> Java -> Editor -> Save Actions -> Configure -> Unnecessary Code -> Remove redundant type arguments (1.7 or higher)

Now I create a Main class:

public class Main 
{
   public static void main(String[] args)
   {
     TestObject o = new TestObject();
     o.setData(new ArrayList<String>());
   }
}

Now I save the file.

I would have expected eclipse to remove the "String" type argument inside the setter on saving the file, but it stayed there.

Any ideas why this is the case (is there a reason for it or did I miss a setting I have to enable?)

Google

Upvotes: 0

Views: 815

Answers (1)

Sumit Singh
Sumit Singh

Reputation: 15906

It only remove for code like below:

List<String> yourList = new ArrayList<String>()
to
List<String> yourList = new ArrayList<>()

If this is passed in method like your code, eclipse will not remove that.

Not sure exactly but as from the below bug looks like its only remove when type arguments is redundant.

Reduce type arguments to diamond <> (1.7 or higher)
o Never o Only if redundant

See [1.7][clean up][quick assist] Remove unnecessary type arguments (was: Suggest to use <> where applicable)

Upvotes: 1

Related Questions