IT/Spring

2021-04-05-deep-copy

봉즙 2023. 2. 28. 08:07

layout : post
title : "Deep copy"

category : Spring

BeanUtils.copyProperties(person1, person2, "name", "phone");

이름과 전화번호 이외의 내용을 person1 → person2로 복사해준다.

원하는 class에 implements Cloneable 을 해준후

public Candidate clone() {
        Candidate candidate = null;
        try {
            candidate = (Candidate) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return candidate;
}