Click to See Complete Forum and Search --> : Clone vs New


agni256
June 6th, 2003, 12:03 PM
Hi,
I am just trying to understand the difference between these two.
Is clone same as New and set all the properites according to cloned object.

object c1= c2.clone();

c1 will be a new object with all the properites set according to
the clone method implementation.

I am trying to understand the difference, any help?

khp
June 6th, 2003, 01:33 PM
Yes, by default the clone method will create a shallow copy of the cloned object.

If you need a deep copy or any other behaviour, you should override the clone method with your own implementation.

dlorde
June 8th, 2003, 02:22 PM
You might find this useful: Cloning in Java (http://www.codeguru.com/forum/showthread.php?s=&postid=660398#post660398).

Clone, sweet clone...