有没有办法将有界泛型类型的数组传递给具有相同泛型类型的参数而不引发 ClassCastException 的方法?:
public class Heap<E extends Comparable> implements java.lang.Cloneable{
private java.util.ArrayList<E> list = new java.util.ArrayList<E>();
public Heap(E[] objects) {
for (int i = 0; i < objects.length; i++) {
add(objects[i]);
}
}
private void add(E newObject){
...
}
@Override
protected Heap<E> clone() {
return new Heap<E>((E[])list.toArray());
}
}