运行时异常java.lang.ClassCastingException
——...
Integer intArr[] = new Integer[arrList.size()];
ArrayList <Integer> arrList =new ArrayList();
intArr=(Integer[])arrList.toArray(); // returns Object class which is downcaste to Integer;
我知道向下转换是不安全的,但为什么会发生这种情况?我也尝试将 to 转换ArrayList
为String
to Integer
,int
但我得到了同样的错误。