What exactly does the clone() method in Java return when used on an array? Does it return a new array with data copied from the original?
Ex:
int[] a
clone() method creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:
x.clone() != x
Will be true, and that the expression:
x.clone().getClass() == x.getClass()
Will be true, but these are not absolute requirements.
While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.
By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().