Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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()]);
Source by pmd.github.io #
 
PREVIOUS NEXT
Tagged: #ClassCastException #Casting #method
ADD COMMENT
Topic
Name
1+1 =