Re: How to implement the clone methods for Custom objects in a hierarchal data structure??
Posted By:
Dinesh_Koppulakonda
Posted On:
Friday, July 11, 2003 11:48 PM
Sorry Guys I missed the "breaks" in my previos post, here is a better version...
If i have a date structure like
HashMap >> myObject >> ArrayList >> anotherObject
( ">>" means "contains")
note: "myObject" and "anotherObject" are custom objects that implement cloneable interface and overrides the clone method of the Object class.
I have 2 questions.....
1)If I call clone method on the HashMap, will it return a deep copy of all the contents? If not what will my "shallow" copy of the above data structure look like?
2)What should be the clone methods of "myobject" and "anotherObject" be like ?
I have just written the follwoing code ... will this suffice??
public Object clone()
{
try{
return super.clone();
}catch(CloneNotSupportedException cn){ return null; }
}