인터페이스를 구현하는 Enum 목록을 사용하여 Interface 목록을 취하는 메서드를 호출하려고합니다.인터페이스를 구현하는 enum 목록이있는 메소드를 호출 할 수없는 이유는 무엇입니까?
public enum Enum implements Interface {
}
이 호출하는 클래스는 다음과 같습니다 :
이 인터페이스를 구현하는 열거입니다public interface Interface {
}
:이 인터페이스
The method method(List<Interface>) in the type Class is not applicable for the arguments (List<Enum>)
이 다음과 같은 컴파일 오류가 있습니다
import java.util.ArrayList;
import java.util.List;
public class Class {
public static void method(List<Interface> list){
}
public static void main(String[] args) {
List <Enum> enumList = new ArrayList<Enum>();
method(enumList); //This line gives the compile error.
}
}
컴파일 오류가 발생하는 이유는 무엇입니까? 나에게 그것은 Enum이 그 인터페이스를 구현하기 때문에 작동 할 것으로 보인다.
[자바 제네릭 (http://stackoverflow.com/questions/1794842/generics-in-java)의 중복 가능성 – Thilo
네, 중복입니다. 내가 더 일찍 찾고 있었을 때 나는 그것을 발견 할 수 없었다. –