该jdk版本为1.8,注释是经过翻译的中英文双语版本,翻译的不一定尽善尽美,欢迎提出意见建议.以下是简单例子. /** *Increases the capacity to ensure that it can hold at least the number of elements specified by the minimum capacity argument. *增加容量,以确保它至少可以容纳由最小容量参数指定的元素数量。 *@param minCapacity the desired minimum capacity *@param限制所需的最小容量 */ private void grow(int minCapacity) { //overflow-conscious code //overflow-conscious代码 int oldCapacity = elementData.length; int newCapacity = oldCapacity + (oldCapacity >> 1); if (newCapacity - minCapacity 0) newCapacity = hugeCapacity(minCapacity); //minCapacity is usually close to size, so this is a win: //minCapacity通常接近于size,所以这是一个优势: elementData = Arrays.copyOf(elementData, newCapacity); } private static int hugeCapacity(int minCapacity) { //if (minCapacity < 0) overflow //如果(minCapacity MAX_ARRAY_SIZE) ? Integer.MAX_VALUE : MAX_ARRAY_SIZE; }
2021-09-13 21:41:33 80B jdk1.8源码 中英文对照注释
1