public Vector(Collection<? extends E> c) {
elementData = c.toArray();
elementCount = elementData.length;
// c.toArray might (incorrectly) not return Object[] (see 6260652)
if (elementData.getClass() != Object[].class)
elementData = Arrays.copyOf(elementData, elementCount, Object[].class);
}红色字体
谢谢
public Vector(Collection<? extends E> c) {
elementData = c.toArray();
elementCount = elementData.length;
// c.toArray might (incorrectly) not return Object[] (see 6260652)
if (elementData.getClass() != Object[].class)
elementData = Arrays.copyOf(elementData, elementCount, Object[].class);
}
public Vector(Collection<? extends E> c)
?:表示通配符;E:表示Collection里的Element(元素);
第二个参数 Collection<? extends E> c 表示的是 Collection c中的元素只能是E及其子类的对象。而泛型E只有E的对象。还有这种形式的List<? Super Child>声明的List 能且仅能存放Child及其父类对象.
boolean addAll(Collection<? extends E> c)将指定 collection 中的所有元素都添加到此 collection 中(可选操作)。如果在进行此操作的同时修改指定的 collection,那么此操作行为是不确定的。(这意味着如果指定的 collection 是此 collection,并且此 collection 为非空,那么此调用的行为是不确定的。) 参数:
c - 包含要添加到此 collection 的元素的 collection
返回:
如果此 collection 由于调用而发生更改,则返回 true
抛出:
UnsupportedOperationException - 如果此 collection 不支持 addAll 方法
ClassCastException - 如果指定 collection 中某个元素的类不允许它添加到此 collection 中
NullPointerException - 如果指定 collection 包含 null 元素,并且此 collection 不支持 null 元素,或者指定的 collection 为 null