Answers for "ClassCastException Casting toArray() method"

0

ClassCastException Casting toArray() method

Collection c = new ArrayList();
Integer obj = new Integer(1);
c.add(obj);

    // this would trigger the rule (and throw a ClassCastException if executed)
Integer[] a = (Integer [])c.toArray();

   // this is fine and will not trigger the rule
Integer[] b = (Integer [])c.toArray(new Integer[c.size()]);
Posted by: Guest on June-22-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language