Deep copy

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

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

원하는 class에 implements Cloneable 을 해준후

1
2
3
4
5
6
7
8
9
public Candidate clone() {
        Candidate candidate = null;
        try {
            candidate = (Candidate) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return candidate;
}