xuriyunhai 发表于 2013-2-3 11:26:09

Java深拷贝

@SuppressWarnings("unchecked")    public static <T> T deepClone(T t) {      ObjectInputStream oi;try {//将对象写到流里ByteArrayOutputStream bo=new ByteArrayOutputStream();ObjectOutputStream oo=new ObjectOutputStream(bo);oo.writeObject(t);//从流里读出来 ByteArrayInputStream bi=new ByteArrayInputStream(bo.toByteArray());oi = new ObjectInputStream(bi);return (T) (oi.readObject());} catch (IOException e) {e.printStackTrace();} catch (ClassNotFoundException e) {e.printStackTrace();}return null;    }  
页: [1]
查看完整版本: Java深拷贝