浅拷贝:指的是你的类本身被拷贝,而没有拷贝类本身属性中的类。
深拷贝:指的是包含类本身和属性类在内的所有类的拷贝。
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Person implements Cloneable{
private String nickname;
private Address address;
@Override
protected Object clone() throws CloneNotSupportedException {
// 浅拷贝
// return super.clone();
// 深拷贝
// return new Person(this.nickname,new Address(this.address.getCity()));
return new Person(this.nickname, (Address) this.getAddress().clone());
}
}