RFR(s): 8060192: Add default method Collection.toArray(generator)
stuart.marks at oracle.com
Wed Dec 6 21:42:27 UTC 2017
On 12/5/17 8:41 PM, Bernd Eckenfels wrote:
> Should the test also check for the case the generator returns under- and oversized arrays?
Did you mean that the default implementation (and various overriding
implementations) of toArray(generator) should do checks on the array that's
returned from the generator? If so, I'm skeptical of the utility of adding such
If the array is too short, ArrayIndexOutOfBoundsException will occur, so no
check is necessary. If the array is too long, it will work, but the application
might have trouble ascertaining the number of elements copied. Presumably it
wouldn't create a too-long array unless it can deal with this. In any case, it
doesn't necessarily seem like this should be an error.
> The default impl looks less efficient than (new T), should it really be removed as a major Javadoc example? (Or maybe add more specific implementations besides ArrayList?)
Although my benchmarks were inconclusive, it doesn't seem like the extra call to
the generator with zero should be a performance problem. Even if this is a
problem, it will disappear as more overrides are added to the system.
More information about the core-libs-dev