Am 09.03.2012 09:16, schrieb Sean Chou:
Hi all,

AbstractCollection.toArray(T[] ) might return a new array even if the given array has enough room for the returned elements when it is concurrently modified. This behavior violates the spec documented in java.util.Collection . This patch checks the size of returned array and copies the elements to return to the given array if it is large enough.

More Questions:

Why don't we have
    public <T super E> T[] toArray(T[] a)  ?
This would prevent from the cast
        r[i] = (T)it.next();

Wouldn't following statement potentially throw a ClassCastException ?
        r[i] = (T)it.next();
... but the doc says, it should throw an ArrayStoreException, if the runtime type of the specified array is not a supertype of the runtime type of every element in this collection.

-Ulf



Reply via email to