J
Jay
Why does the following code produce a ClassCastException?
ArrayList list = new ArrayList();
list.add(new Object[]{"Test1", "..."});
list.add(new Object[]{"Test2", "..."});
list.add(new Object[]{"Test3", "..."});
Object ar[][] = (Object[][]) list.toArray();
The last line causes a ClassCastException... Yet, list.toArray() is
just an array of objects which are themselves arrays of objects. So
list.toArray is an Object[][], conceptually. Why does Java complain?
ArrayList list = new ArrayList();
list.add(new Object[]{"Test1", "..."});
list.add(new Object[]{"Test2", "..."});
list.add(new Object[]{"Test3", "..."});
Object ar[][] = (Object[][]) list.toArray();
The last line causes a ClassCastException... Yet, list.toArray() is
just an array of objects which are themselves arrays of objects. So
list.toArray is an Object[][], conceptually. Why does Java complain?