A deep copy of a Java object, regardless of the parameters in the object, such as String, array, object type, or object type with an object type parameter.
And this copied object does not need to implement the serializable interface.
Import Java.io.ByteArrayInputStream;
Import Java.io.ByteArrayOutputStream;
Import java.io.IOException;
Import Java.io.ObjectInputStream;
Import Java.io.ObjectOutputStream;
/** *
cloning operation class
* @author Liguohui
* * */public
class Cloneoper {
/**
* deep copy
* @param obj
* @return
*
/@SuppressWarnings ("unchecked") public
static <T> t Deepcloneobject (t obj) {
try {
Bytearrayoutputstream byteout = new Bytearrayoutputstream ();
ObjectOutputStream out = new ObjectOutputStream (byteout);
Out.writeobject (obj);
Bytearrayinputstream Bytein = new Bytearrayinputstream (Byteout.tobytearray ());
ObjectInputStream in =new ObjectInputStream (Bytein);
Return (T) in.readobject ();
} catch (IOException e) {
e.printstacktrace ();
} catch (ClassNotFoundException e) {
e.printstacktrace ();
}
return null;
}
}