1. 测试主类
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.SerializationUtils;
@Slf4j
public class JBase {
@SneakyThrows
public static void main(String[] args) throws ClassNotFoundException {
TestVO testVO = new TestVO();
testVO.setId(1);
testVO.setName("name_1");
testVO.setChild(new TestVO());
TestVO testVO2 = TestVO.class.getDeclaredConstructor().newInstance();
TestVO testVO3 = SerializationUtils.clone(testVO);
TestVO testVO4 = testVO.clone();
System.out.println(testVO.getName());
}
}
2. 测试类
import lombok.Data;
import lombok.SneakyThrows;
import java.io.Serializable;
@Data
public class TestVO implements Serializable,Cloneable {
private Integer id;
private String name;
private TestVO child;
@SneakyThrows
@Override
public TestVO clone(){
Object clone = super.clone();
return (TestVO)clone;
}
}