Java Reference
In-Depth Information
/**
* Overrides Object's clone method to create a deep
copy
*
* @return
*/
public Object clone() {
Object obj = null;
try {
ByteArrayOutputStream baos = new
ByteArrayOutputStream();
ObjectOutputStream oos = new
ObjectOutputStream(baos);
oos.writeObject(this);
oos.close();
ByteArrayInputStream bais = new
ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new
ObjectInputStream(bais);
obj = ois.readObject();
ois.close();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
return obj;
}
/**
* Overrides Object's clone method to create
a shallow copy
*
* @return
*/
public Object shallowCopyClone() {
Search WWH ::




Custom Search