Hi! What's the difference between cloning and assignment? example: int p = new int; int p2 = (int)p.clone(); VS int p = new int; int p2 = p; Thanks in advance.
posted 14 years ago
in this case there is no difference. Its like copying the reference of one array to another. Array Objects has their own overriden clone() method, which only does shallow copying. i.e. something like assinging the an array reference to another array reference variable. Inorder to get your own clone behaviour, you need to write a public method clone() in your class which must call the protected clone() method inherited from Object method. or you can implement the Cloneable interface. Cheers Siva