这是 Josh bloch 编写的代码(Linkedlist.java)
* @throws NullPointerException if the specified collection is null
*/
public boolean addAll(int index, Collection<? extends E> c) {
checkPositionIndex(index);
Object[] a = c.toArray();
int numNew = a.length;
if (numNew == 0)
return false;
Node<E> pred, succ;
if (index == size) {
succ = null;
pred = last;
} else {
succ = node(index);
pred = succ.prev;
}
在这里,我没有看到 Collection c 的任何空 ptr 检查。相反有效的java非常强调参数验证,强调空指针检查。If an invalid parameter value is passed to a method and the method checks its parameters before execution, it will fail quickly and cleanly with an appropriate exception.
我需要知道我错过了什么?换句话说,他为什么不对 addAll 函数进行空值检查?