Java 深克隆

来源:互联网 发布:淘宝发顺丰多少钱 编辑:程序博客网 时间:2024/05/22 09:38

深层克隆实现:

Java代码

  1. static void testSerial(int times) throws IOException, ClassNotFoundException {  
  2.         ByteArrayOutputStream bos;  
  3.         ObjectOutputStream oos;  
  4.         ByteArrayInputStream bin;  
  5.         ObjectInputStream ois;  
  6.         long startTime = System.currentTimeMillis();  
  7.   
  8.         for (int i = 0; i < times; i++) {  
  9.             bos = new ByteArrayOutputStream();  
  10.             oos = new ObjectOutputStream(bos);  
  11.             oos.writeObject(vb);  
  12.             bin = new ByteArrayInputStream(bos.toByteArray());  
  13.             ois = new ObjectInputStream(bin);  
  14.             ois.readObject();  
  15.         }  
  16.   
  17.         System.out.println("testSerial:" + (System.currentTimeMillis() - startTime));  
  18.     } 
原创粉丝点击