public E remove(int index) {
# 检查remove源码是,发现 其中对index 的检查仅限于上溢出检查
# 没有显示的对下溢出进行检查?
rangeCheck(index);
modCount++;
# 在此处,elementData 是一个Object[] 对象实例,会自动对下溢出进行检查 !!!
E oldValue = elementData(index);
int numMoved = size - index - 1;
if (numMoved > 0)
System.arraycopy(elementData, index+1, elementData, index,
numMoved);
elementData[--size] = null; // clear to let GC do its work
return oldValue;
}
# 上溢出检查,抛出 IndexOutOfBoundsExceptions异常
private void rangeCheck(int index) {
if (index >= size)
throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)