classcastexception casting toarray 28 29 method

Solutions on MaxInterview for classcastexception casting toarray 28 29 method by the best coders in the world

showing results for - "classcastexception casting toarray 28 29 method"
Juan Pablo
26 Feb 2016
1Collection c = new ArrayList();
2Integer obj = new Integer(1);
3c.add(obj);
4
5    // this would trigger the rule (and throw a ClassCastException if executed)
6Integer[] a = (Integer [])c.toArray();
7
8   // this is fine and will not trigger the rule
9Integer[] b = (Integer [])c.toArray(new Integer[c.size()]);
10