标题: java对象的克隆方法 [打印本页] 作者: 胡述灵 时间: 2015-8-28 10:46 标题: java对象的克隆方法 class CloneClass implements Cloneable{
public int aInt;
public Object clone(){
CloneClass o = null;
try{
o = (CloneClass)super.clone();
}catch(CloneNotSupportedException e){
e.printStackTrace();
}
return o;
}
}
-----------------------------------------------
ByteArrayOutputStream
byteOut = new ByteArrayOutputStream();
ObjectOutputStream out
= new ObjectOutputStream(byteOut);
out.writeObject(combo);
ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
ObjectInputStream in
=new ObjectInputStream(byteIn);
JComboBox comb2 = (JComboBox)in.readObject();