今天在看ArrayList源码,有如下困惑,希望得到大神们的解答。
在ArrayList源码中定义了两个一模一样的数据结构,如下:
private static final Object[] EMPTY_ELEMENTDATA = {};
private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {};
官网给出的解释是这样子的:
private static final Object[] EMPTY_ELEMENTDATA = {};
Shared empty array instance used for empty instances.
而,另外一个:
private static final Object[] DEFAULTCAPACITY_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.
求解答啊,谢谢~~~
而且,本人吃惊的发现,DEFAULTCAPACITY_EMPTY_ELEMENTDATA 这个东西是JDK 1.8中才加进来的,我就更加神奇了,为什么JDK 1.8中要加入这个呢?
月关宝盒
相关分类