代码如下:
import java.io.Serializable;
public class CloneUtils {
public static <T extends Serializable> T Clone(T obj) {
T cloneObj = null;
try {
//字节数组流写入内存缓冲区
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
oos.close();
//读取内存缓冲区数据,转换为字节
ByteArrayInputStream bai = new ByteArrayInputStream(
baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bai);
cloneObj = (T) ois.readObject();
ois.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return cloneObj;
}代码如下:
import java.io.Serializable;
public clas