H
hitesh
Is this a right way to clone a complex Object
public Object clone(){
try {
//Write the Complex object to the OutputStream
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(this);
oos.flush();
//Read the Complex Object from the InputStream
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
return ois.readObject();
}
catch (Exception e) {
// This should never happen
throw new MyException("Cannot Clone Complex Object. " + e.toString());
}
}
public Object clone(){
try {
//Write the Complex object to the OutputStream
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(this);
oos.flush();
//Read the Complex Object from the InputStream
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
return ois.readObject();
}
catch (Exception e) {
// This should never happen
throw new MyException("Cannot Clone Complex Object. " + e.toString());
}
}