ArrayList源码阅读之EMPTY_ELEMENTDATA和DEFAULTCAPACITY_EMPTY_ELEMENTDATA区别
/**
* Shared empty array instance used for empty instances.
*/
private static final Object[] EMPTY_ELEMENTDATA = {};
/**
* Shared empty array instance used for default sized empty instances. We
* distinguish this from EMPTY_ELEMENTDATA to know how much to inflate when
* first element is added.
*/
private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {};
* Shared empty array instance used for empty instances.
*/
private static final Object[] EMPTY_ELEMENTDATA = {};
/**
* Shared empty array instance used for default sized empty instances. We
* distinguish this from EMPTY_ELEMENTDATA to know how much to inflate when
* first element is added.
*/
private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {};
EMPTY_ELEMENTDATA:共享的空数组实例用于空实例。
DEFAULTCAPACITY_EMPTY_ELEMENTDATA:共享的空数组实例用于默认大小的空实例。我们将其与EMPTY_ELEMENTDATA区分开,以便在添加第一个元素时知道要扩容多少。
总结:EMPTY_ELEMENTDATA表示容量为0的空ArrayList,而DEFAULTCAPACITY_EMPTY_ELEMENTDATA表示容量为默认值的空ArrayList。