ArrayList<String> al=new ArrayList<String>();
al.add("123");
ArrayList<String> bl;
bl=al.clone();                  --这句报Type safety: Unchecked cast from Object to ArrayList<String>
警告改为bl=(ArrayList<String>)al.clone();附带问一个问题,java中如何检测内存泄露。在MyEclipse中有没有什么好的内存泄露检测的方法。

解决方案 »

  1.   

    内存泄露问题,向你推荐做windowbuilderpro的instantiations公司的产品:CodePro Profiler™。
    windowbuilderpro实在做得太好了,他们的CodePro Profiler™也相当不错,值得一试。
      

  2.   

    好象改了也会报吧...
    留着不好吗?
    必要的话恐怕需要写一个Ybhzf类继承ArrayList,然后重写clone()方法...
      

  3.   

    ArraysList类的代码:
        public Object clone() {
    try {
        ArrayList<E> v = (ArrayList<E>) super.clone();
        v.elementData = Arrays.copyOf(elementData, size);
        v.modCount = 0;
        return v;
    } catch (CloneNotSupportedException e) {
        // this shouldn't happen, since we are Cloneable
        throw new InternalError();
    }
        }可以看到它已经重写了clone方法,没有特殊需要的话,我想你不用重写吧,不过不明白它为什么以Object类型返回
    我想你只能强制转换吧。