TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
TIOBE - Java Coding Standard
Search

Rule:  Design15Checked automatically with code checker

Synopsis:This call to Collection.toArray() may be optimizable
Language:Java
Severity Level:5
Category:Design


Description:
A call to Collection.toArray can use the Collection's size vs an empty Array of the desired type.
class Foo {
 void bar(Collection x) {
   // A bit inefficient
   x.toArray(new Foo[0]);
   // Much better; this one sizes the destination array, avoiding
   // a reflection call in some Collection implementations
   x.toArray(new Foo[x.size()]);
 }
}