实现Cloneable接口的bean
@Data
public class Test implements Cloneable{
private String name;
private Integer years;
private Integer sex;
//重写深度拷贝的方法
public Test clone() throws CloneNotSupportedException {
Test cloned= (Test) super.clone();
return cloned;
}
}
在方法中调用
public class main {
public static void main(String[] args) throws CloneNotSupportedException {
Test t = new Test();
t.setSex(1);
t.setName("1111");
t.setYears(12);
Test clone = t.clone();
System.out.println(clone.getSex());
}
}