Reputation: 122062
I have a bit of code:
class MyClass<RCM>
private List<RCM> allPreExistingConfigsForCodes() {
if(this.allCodesForThisType.size() == 0)
return new ArrayList<RCM>(0);
IntelliJ is telling me I should replace new ArrayList<RCM>
with new ArrayList<>
what would that mean?
Upvotes: 42
Views: 12298
Reputation: 57192
Are you using Java 7? If so, it is trying to take advantage of the new "diamond notation."
Upvotes: 12
Reputation: 55213
From the Java Tutorials generics lesson:
In Java SE 7 and later, you can replace the type arguments required to invoke the constructor of a generic class with an empty set of type arguments (
<>
) as long as the compiler can determine, or infer, the type arguments from the context. This pair of angle brackets,<>
, is informally called the diamond. For example, you can create an instance ofBox<Integer>
with the following statement:
Box<Integer> integerBox = new Box<>();
Upvotes: 53