lists.newArrayList()
List list = Lists.newArrayList();
源码
public static <E> ArrayList<E> newArrayList() {
return new ArrayList();
}
@CanIgnoreReturnValue
@GwtCompatible(
serializable = true
)
public static <E> ArrayList<E> newArrayList(E... elements) {
Preconditions.checkNotNull(elements);
int capacity = computeArrayListCapacity(elements.length);
ArrayList<E> list = new ArrayList(capacity);
Collections.addAll(list, elements);
return list;
}
lists.ArrayList()
List list = new ArrayList();
new arraylist() :
Lists和Maps是两个工具类, Lists.newArrayList()其实和new ArrayList()几乎一模一样, 唯一它帮你做的(其实是javac帮你做的), 就是自动推导(不是"倒")尖括号里的数据类型.