Deep Copy in Java
Posted on 2010-09-08
Since I've been programming a lot with C and C++, I am a bit confused as to how I'm going to implement something in Java since it manages memory it's own way. Take the following steps for example:
I create a hierarchy of classes, and create an instance of an this object (polymorphism stuff) with specific data values and store it.
Simple enough right?
I will call this my TEMPLATE OBJECT
Now, I want to copy my template object to another object called HELLO, and it needs to be a DEEP COPY because I want to change HELLO in every way, and have the TEMPLATE object unaltered.
How do I do this in Java??
I'm confused because you can't specifically code in a copy constructor or anything like that in Java.
Can I do something like. public example_object temp = new example_object(TEMPLATE) --??
I REALLY NEED HELP ON THIS ONE. It's for homework and I gotta get crackin, I'll be sitting by this post. Lets see what ya'll think.