当前位置:网站首页>IO流實現深克隆

IO流實現深克隆

2021-11-25 17:12:32 qq619c5952a065f

       
@Test
public void test2() throws Exception {
Boy person = new Boy(18,"程柏薹");

ByteArrayOutputStream baos = new ByteArrayOutputStream();

ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(person);

ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
Boy p2 = (Boy) ois.readObject();
System.out.println(person+","+person.hashCode());
System.out.println(p2+","+p2.hashCode());

}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.

 

版权声明
本文为[qq619c5952a065f]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/11/20211125171114381h.html

随机推荐