Item 52. Overloading
class CollectionClassifier {
public static String classify(Set<?> s) {
return "์งํฉ";
}
public static String classify(List<?> lst) {
return "๋ฆฌ์คํธ";
}
public static String classify(Collection<?> c) {
return "๊ทธ ์ธ";
}
public static void main(String[] args) {
Collection<?>[] collections = {
new HashSet<String>(),
new ArrayList<BigInteger>(),
new HashMap<String, String>().values()
};
for (Collection<?> c : collections) {
// ์ปดํ์ผํ์์ c๋ ํญ์ Collection<?> ํ์
์ด๋ฏ๋ก ๋ชจ๋ "๊ทธ ์ธ" ์ถ๋ ฅ
System.out.println(classify(c));
}
}
}๋ค์ค์ ์ ํผ๋ ํํผ ๋ฐฉ๋ฒ
์์ฑ์
๋ค์ค์ ์ ํผ๋์ผ๋ก ์๊ธฐ๋ ์์
List.remove(int index) vs List.remove(Object o)
Last updated