Item 30 - 이왕이면 제네릭 메서드로 만들라
이왕이면 제네릭 메서드로 만들라
Intro
문제가 있는 제네릭 메서드 작성법
class Example {
public static Set union(Set s1, Set s2) {
Set result = new HashSet(s1);
result.addAll(s2);
return result;
}
}Unchecked call to 'HashSet(Collection<? extends E>)' as a member of raw type 'java.util.HashSet'
Unchecked call to 'addAll(Collection<? extends E>)' as a member of raw type 'java.util.Set'경고를 없애기 위해 타입 안전하게 만드는 방법
항등 함수(identity function)를 담은 클래스를 만드는 경우
마무리
정리
Last updated