Request for review : 7121314 : Behavior mismatch between AbstractCollection.toArray(T[] ) and its spec

Ulf Zibis Ulf.Zibis at
Tue Mar 13 19:16:57 UTC 2012

Am 10.03.2012 13:52, schrieb David Holmes:
> On 10/03/2012 12:02 PM, Ulf Zibis wrote:
>> Why don't we have
>> public <T super E> T[] toArray(T[] a) ?
>> This would prevent from the cast
>> r[i] = (T);
> It's too late to change the method signature now.
Sorry about my english, I meant why don't we have had ...
In other words, has there been a reason that it was not like that from the beginning?

> Wouldn't following statement potentially throw a ClassCastException ?
>> r[i] = (T);
> Apparently not. I passed in a String[] when it should be Object[] and got ArrayStoreException. 
> Checking the bytecode I don't see a checkcast.
Thanks, checking that out.


More information about the core-libs-dev mailing list