I'm trying to figure out implementing the clone() method of Object. I have a class with a few data memebers that I thought I'd try it out on - a node class for a linked list.
So, here's the class:
public class HashListNode implements Cloneable
{
private String data;
private HashListNode nextNode;
/* other methods and such */
public Object clone() throws CloneNotSupportedException
{
final HashListNode theClone = (HashListNode)super.clone();
if( this.nextNode != null)
{
theClone.nextNode = (HashListNode)this.nextNode.clone();
}
return theClone;
}
}
So, it seems that what's happening is when I call super.clone(), I'm calling Object's clone method, correct? What I don't understand, is will that method be able to deal with the String?
I can't seem to figure out if I have the hang of writing clone methods.
I am aware that it might not be too important to write one for this class, it just happened to be a simple class that was written recently.
Thanks for any help.