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

Perhaps because it is not legal Java?

Éamonn


On 13 March 2012 12:16, Ulf Zibis <ulf.zi...@gmx.de> wrote:
>
> 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.next();
>>
>>
>> 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)it.next();
>>
>>
>> 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.
>
> -Ulf
>

Reply via email to