Tuesday, April 7, 2009

Java Object Clone Sample Code

To create a deep copy of Java object you should implement "Cloneable" interface and override clone() method. Here is the sample code:

class MyClass implements Cloneable
{
public Object clone()
{
try
{
return super.clone();
}
catch(CloneNotSupportedException ex)
{
return null;
}
}
}

No comments:

Post a Comment

Search