c.toArray might (incorrectly) not return Object[] (see 6260652)
Doug Lea
dl at cs.oswego.edu
Fri May 22 11:31:50 UTC 2009
David Holmes - Sun Microsystems wrote:
> Thanks for the info, one query though ...
>
> Ummm why didn't it just use:
>
> elementData = c.toArray(new Object[c.size()]);
>
Because "c" might be a concurrent collection, so you
don't want to independently call c.size(). Notice
that AbstractCollection correctly implements
toArray() even for such collections but cannot do so
for toArray(T[] a) because it must interpret
a.length as the required size.
-Doug
More information about the core-libs-dev
mailing list