请问为什么Object类型数组转型为泛型数组运行会报错?
例如:
Object[] o = new String("str","333");
String[] str = (String[])o;
System.out.println(str);//此处运行不报错
Object[] os = new Object[]{new ArrayList<People>(),new ArrayList<People>()};
ArrayList<People>[] als = (ArrayList<People>[])os;
System.out.println(als[0].get(0).getName());//此处运行出错错误提示:[Ljava.lang.Object; cannot be cast to [Ljava.util.ArrayList;
为什么不能将Object强制转型为ArrayList呢转型Java

解决方案 »

  1.   

    Object[] o = new String("str","333");这句话对???
      

  2.   

    有,think in java 里面讲到了
      

  3.   

    感觉是类型不能匹配的原因 泛型的话也应该写ArrayList< ArrayList<People>()>[] als这样的泛型吧!!!!
      

  4.   

    Object[] o = new String("str","333");
    Type mismatch: cannot convert from String to Object[]
      

  5.   

    我刚刚上网帮你搜了一下    发现只有什么伪方案才能解决  
    http://www.iteye.com/topic/320161
    有兴趣去看看吧