Adding default method to java.lang.Cloneable

Rémi Forax forax at
Fri Mar 2 07:30:41 PST 2012

On 03/02/2012 04:13 PM, Florian Weimer wrote:
> * Rémi Forax:
>> I've tried to add a default method to java.lang.Cloneable
>> in order to be able to call it on an array
>> (all arrays inherits from Object and implements Cloneable and Serializable).
>> But the VM doesn't like that :)
>> I think it's a bug.
> The clone method is very special.  It's not visible using reflection...

clone() is not the only method hidden when you use the reflection API,
I know, but in my opinion it's a slighly different problem.

You can call clone() on an array in Java.
You're right that there is a special code in the compiler for clone
which calls Object.clone() instead of int[].clone()

But it that case, this should work:
     int[] array = new int[] {2, 4 };
     Cloneable c = array;

But it doesn't work.


More information about the lambda-dev mailing list