private T[] entry;
....
entry = new Object[2*entry.length];
上面的方法为什么不可以? 应该怎么样?

解决方案 »

  1.   

    请问: entry.length 到底是多少?
      

  2.   


     Object[] objs = new Object[10];
            Object[] temp = objs;
            objs = new Object[objs.length*2];没有问题。
    你报什么错误?
    不会是都直接写在class定义里了吧,或者开始数组为空的时候就使用数组的length了?
      

  3.   


    System.out.println(Double.SIZE);}
      

  4.   


    public class ExpandableArrayList<T> { private T[] entry;
    private int length;
    private static int initialCapacity = 10;

    public ExpandableArrayList(int maxSize){
    length = 0;
    List = (T[] new Object[maxSize]);
    }

    //在末尾插入新元素
    public boolean add(T newEntry){      
    if(isArrayFull())    //如果数组满了   使用isArrayFull方法判断
    doubleArray();   //那么就扩大一倍 使用doubleArray方法
    entry[length] = newEntry;
    length++;
    return true;
    }

    public boolean isArrayFull(){
    return length == entry.length;
    }

    private void doubleArray(){
    T[] oldEntry = entry;
    int oldSize = oldEntry.length;
    //entry = new Object[2*oldSize]; 这句是错误的 我就想知道这个是为什么
    }
    public static void main(String[] args) {
    // TODO Auto-generated method stub }}
      

  5.   

     entry = (T[])new Object[2*oldSize]; 
      

  6.   


    先用数组实现线性表 ArrayList实现 是后面一节 呵呵 给分了