반응형 얕은복제1 [JAVA] 객체 복제(clone)와 Shallow Copy, Deep Copy 객체를 복제하기 위해서는 Cloneable을 구현하고, clone() 메소드를 오버라이드하면 되서 간단하다! @Getter @Setter public class Person implements Cloneable{ private String name; private int age; @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } } 그리고 아래와 같이 person1.clone(); 을 사용하여 person1의 객체를 복제하였다. Person person1 = new Person(); person1.setName("홍길동"); person1.setAge(30); try { Person pers.. 2022. 2. 16. 이전 1 다음 728x90 반응형