gpt4 book ai didi

java - ArrayList 公共(public)构造函数 - "Constructs an empty list with an initial capacity of ten"- 在哪里?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:14:55 24 4
gpt4 key购买 nike

<分区>

请注意,它不是 Why start an ArrayList with an initial capacity? 的副本

查看 java.util.ArrayList 类的源代码,至少从 java 1.8 开始,我看到以下代码:

/**
* Constructs an empty list with an initial capacity of ten.
*/
public ArrayList() {
this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA;
}

在哪里

private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {};

虽然javadoc官方声明:

Constructs an empty list with an initial capacity of ten.

我概述:...初始容量为 10。这在哪里?

我是完全疯了并且遗漏了什么,还是这里只是一个 javadoc 错误?

更新:它看起来像以前的 java 1.8:

public ArrayList(int initialCapacity) {
super();
if (initialCapacity < 0)
throw new IllegalArgumentException("Illegal Capacity: "+
initialCapacity);
this.elementData = new Object[initialCapacity];
}

/**
* Constructs an empty list with an initial capacity of ten.
*/
public ArrayList() {
this(10);
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com