Request for review : 7121314 : Behavior mismatch between AbstractCollection.toArray(T[] ) and its spec (original) (raw)
Eamonn McManus eamonn at mcmanus.net
Wed Mar 14 04:49:55 UTC 2012
- Previous message: Request for review : 7121314 : Behavior mismatch between AbstractCollection.toArray(T[] ) and its spec
- Next message: Request for review : 7121314 : Behavior mismatch between AbstractCollection.toArray(T[] ) and its spec
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Why don't we have public 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.Zibis at 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[] 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
- Previous message: Request for review : 7121314 : Behavior mismatch between AbstractCollection.toArray(T[] ) and its spec
- Next message: Request for review : 7121314 : Behavior mismatch between AbstractCollection.toArray(T[] ) and its spec
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]