collections1 방어적 복사 방어적 복사가 필요한 이유 객체 내에 List 같은 Collections 객체를 필드로 가지면 final로 선언해도 외부에서 .add로 조작이 가능하다. 이런 조작을 방어하기 위해 방어적 복사가 필요하다.public class Store { private final String name; private final List items; public Store(String name, List items) { this.name = name; this.items = items; // 외부 리스트를 그대로 받음 } public List getItems() { return items; // 내부 리스트를 그.. 2026. 6. 15. 이전 1 다음