Item 30. Generic Method
class Test {
public static <E> Set<E> union(Set<E> s1, Set<E> s2) {
Set<E> result = new HashSet<>(s1);
result.addAll(s2);
return result;
}
public static void main(String[] args) {
Set<String> a = Set.of("a", "b", "c");
Set<String> b = Set.of("d", "e", "f");
Set<String> c = union(a, b);
}
}์ ๋ค๋ฆญ ์ฑ๊ธํด ํฉํฐ๋ฆฌ
์ฌ๊ท์ ํ์
ํ์ (recursive type bound)
Last updated