지네릭 클래스1 [Java] 지네릭스_제한된 지네릭 클래스 타입 매개변수 T에 지정할 수 있는 타입의 종류를 제한해보자 class FruitBox { ArrayList list = new ArrayList(); ... } FruitBox appleBox = new FruitBox(); // OK FruitBox toyBox = new FruitBox(); // 에러. Toy는 Fruit의 자손이 아님 ※ 인터페이스를 구현할 때도 'implements'가 아닌 'extends'를 사용 interface Eatable {} class FruitBox { ... } // 클래스 Fruit의 자손이면서 Eatable 인터페이스도 구현해야 한다면 class FruitBox { ... } 2022. 7. 29. 이전 1 다음