Reputation: 16089
While learning GWT I faced another type of initialization. I'm wondering what is the difference between:
1) List<T> = new ArrayList<T>();
and
2) List<T> = Lists.newArrayList();
Which one has advantages and why?
Upvotes: 1
Views: 1008
Reputation: 9505
I can only suppose:
When you work with generics it's not convenient to set T both in List<T>
and new ArrayList<T>();
To resolve this drawback static helper methods are used:
List<T> = Lists.newArrayList();
Here type T is defined via type inference. A a rule such methods are implemented like this:
public static <T> List<T> newArrayList() {
return new ArrayList<T>();
}
Upvotes: 2