clone != original true
clone.getClass() == original.getClass() true
clone.equals(original) true
class Test implements Cloneable {
...
@Override
protected Object clone() throws CloneNotSupportedException{
return super.clone();
}
...
}
그냥 인스턴스 클로닝 하는 것 생각하면 됨
하지만 Object의 clone 메소드는 shallow copy를 지원하기 때문에 deep copy를 구현하고 싶다면 별도의 작업이 필요함
장점
(1) 복잡한 객체를 만드는 과정을 또 다시 반복하지 않아도 된다.
(2) shallow copy를 해도 되는 상황이라면 네트워크나 db 작업을 통해 생성된 내부 객체를 재활용할 수 있다.
(3) 추상적인 타입의 객체를 리턴할 수 있다.