public class aaaa {
public static void main(String[] args) throws Exception {
Address address = new Address("shen");
Person person1 = new Person("lid", address);
Person person2 = (Person) deepCopy(person1);
System.out.println(person1 == person2); // false
System.out.println(person1.getAddress() == person2.getAddress()); // false
}
static Object deepCopy(Object obj) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
return ois.readObject();
}
static class Person implements Serializable {
private String name;
private Address address;
public Person(Str
10-06
333
04-09