



























代码
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;/**
* @author wangyong
*
*/
public class FormTest {public static Object objectCopy(Object sourceObj) //throws CloneNotSupportedException
{
//实现深克隆(即深复制)
try
{
//将对象写到流里
ByteArrayOutputStream bo=new ByteArrayOutputStream();
ObjectOutputStream oo=new ObjectOutputStream(bo);
oo.writeObject(sourceObj);//源对象
//从流里读出来
ByteArrayInputStream bi=new ByteArrayInputStream(bo.toByteArray());
ObjectInputStream oi=new ObjectInputStream(bi);
return(oi.readObject());//目标对象
}
catch(Exception ex)
{
ex.printStackTrace();
return null;
}
}
/**}
class A implements Cloneable,Serializable}
}
class B implements Serializable此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。