JDK-6201178 : (coll) Add E[] toArray(Class) so that an array instance is not required
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-11-29
  • Updated: 2012-10-08
  • Resolved: 2004-11-29
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
* Add E[] toArray(Class<T>) so that an array instance (like (Foo[])toArray(new Foo[0]) is not required).  Get rid of E[] toArray(E[]).


JUSTIFICATION :
This is one of many RFEs produced from a community discussion at
http://forums.java.net/jive/thread.jspa?threadID=143.  Further
justification could typically be found at the given link or off a
thread listed at the given link.

Why does one need to have an array instance for toArray (??).  I see this as a deficiency in obtaining the class representation of an int array.  Almost _every_ time i've seen toArray being used or being used by myself there has been a zero length array.  E[] toArray(Class<E> classType) should be sufficent.


Comments
EVALUATION This is a duplicate of 5072831. In addition, the submitter asks for the motivation behind passing an array instance to the method toArray. As the documentation explains, the passed array will be used to hold the elements if it is big enough. This is very useful as the same array can be reused avoiding allocation which will delay garbage collection and thus improve performance in some scenarios. ###@###.### 2004-11-29 20:03:38 GMT
29-11-2004