아이템26 로 타입은 사용하지 말라
Effective Java 3e 아이템 26를 요약한 내용 입니다.
public class StampCollection {
private final Collection stamps = ...;
public static void main(String[] args) {
StampCollection stamps = new StampCollection();
// 실수로 동전을 넣는다.
stamps.add(new Coin(...)); // "unchecked call" 경고를 내뱉는다.
for (Iterator i = stamps.iterator(); i.hasNext();) {
Stamp stamp = (Stamp) i.next(); // ClassCastException을 던진다.
stamp.cancel();
}
}List와 List의 차이는 무엇일까?
Set과 Set<?>의 차이는 무엇일까?
로 타입을 쓰지 말라는 규칙에도 예외는 있다.
정리
Last updated