如何使以下代码完全通用?
为什么我不允许写:
private E[]store = new E[length];
import java.util.Arrays;
public class MyArrayList<E> {
private int size = 0;
private int length = 10;
private Object [] store = new Object[length];
public E get(int index){
return (E)store[index];
}
public void add(E item){
if(size >= store.length -5){
increment(store);
}
store[size++] = item;
}
private <T> void increment(T[] store2) {
store = Arrays.copyOf(store2, store2.length * 2);
}
public int size(){
return size;
}
}