博文

目前显示的是 七月, 2021的博文

Java-deepcopy

Reference:  https://www.baeldung.com/java-immutable-object From: https://github.com/eugenp/tutorials/tree/master/core-java-modules/core-java-lang-oop-patterns/src/main/java/com/baeldung/deepcopy package com.baeldung.deepcopy; import java.io.Serializable; public class Address implements Serializable, Cloneable {     @Override     public Object clone () {         try {             return (Address) super.clone();         } catch (CloneNotSupportedException e) {             return new Address(this.street, this.getCity(), this.getCountry());         }     }     private static final long serialVersionUID = 1740913841244949416L;     private String street;     private String city;     private String country;     public Address(Address that) {         this(that.getStreet(), that.getCity(), that.getCountry());     }     public Address(String street, String city, String country) {         this.street = street;         this.city = city;         this.country = country;     }     public Address() {