What is the convention for instantiating collections of user defined types?
coding-style, java, java-7, list, netbeans-7
Solution
ArrayList<MatchingLine> matchingLines = new ArrayList<>();
This is a new feature in Java 7 called `diamond operator`.
Problem
I have a class called MatchingLine ``` public class MatchingLine implements Comparable { private String matchingLine; private int numberOfMatches; // constructor... // getters and setters... // interface method implementation... } ``` I am using this class in an ArrayList as follows - ``` ArrayList<MatchingLine> matchingLines = new ArrayList<MatchingLine>(); ``` However, the Netbeans IDE puts a note beside this statement and says, ``` redundant type arguments in new expression (use diamond operator instead) ``` and it suggests that I use - ``` ArrayList<MatchingLine> matchingLines = new ArrayList<>(); ``` I always thought the former style was the convention? Is the latter style the convention?