array clone() vs Arrays.copyOf()

David Holmes David.Holmes at oracle.com
Wed Apr 27 09:19:49 UTC 2011


Ulf Zibis said the following on 04/27/11 19:09:
> Am 27.04.2011 02:34, schrieb David Holmes:
>>
>> Actually my comments more a response to Remi's assertion that clone 
>> should have been used instead, without giving any technical rationale 
>> as to why clone would be better, and so much better that it warranted 
>> Lance changing the code.
>>
>> Personally I think we should be steering people to Arrays.copyOf for 
>> all their array copying needs.
> Hm, why?

One API to learn that covers all the array-copying needs.

>> clone() is effectively legacy code.
> What does that mean?

Just that it is an old mechanism that has been around for a long time, 
is limited to one specific use-case and has been made somewhat redundant 
by the newer APIs.

> I prefer clone():
> - less to type
> - better to read, especially in looong code lines, e.g. as method call 
> argument

True. Would be nice if defender methods were expanded to allow you to do 
anArray.copyOf()

> - in-advanced reader potentially has less need to refer the doc
> - potentially faster, at least in interpreter and C1?

I don't have the numbers one way or the other.


> BTW: Did you answer to the wrong thread (see attached screen shot) ? 
> That was the reason why I came aware about this post ;-)

That's weird. No I only answered direct to Stuarts email.

Cheers,
David

> 
> ------------------------------------------------------------------------
> 



More information about the core-libs-dev mailing list