Collections.EMPTY_LIST:
public class Collections {
public static final List EMPTY_LIST = new EmptyList<>();
}
private static class EmptyList<E>
extends AbstractList<E>
implements RandomAccess, Serializable {
private static final long serialVersionUID = 8842843931221139166L;
......
}
Collections.emptyList():
Class Collections{
public static final <T> List<T> emptyList() {
return (List<T>) EMPTY_LIST;
}
public static final List EMPTY_LIST = new EmptyList<>();
}
private static class EmptyList<E>
extends AbstractList<E>
implements RandomAccess, Serializable {
private static final long serialVersionUID = 8842843931221139166L;
......
}
ArrayList:
Class ArrayList{
transient Object[] elementData;
private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {};
public ArrayList() {
this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA;
}
}
小结:Collections.EMPTY和Collections.empty()都是空列表,并且是共用同一个,因为EMPTY_LIST是static修饰的(public static final List EMPTY_LIST = new EmptyList<>();),区别是emptyList()可以通过泛型指定返回类型。而new ArrayList(),每次创建的对象都是不同的,所以相比而言会占用空间。