여기에서 문제와 가능한 설명을 지적 할 수 있다면 큰 도움이 될 것입니다.ArrayList 및 다형성
class Parent{}
public class ChildClass extends Parent{
/*Main class*/
public static void main(String[] args) {
ArrayList<ChildClass> a3 = new ArrayList<ChildClass>();
foo(a3);
}
/*another function*/
static void foo(ArrayList<Parent> obj) {
}
다음과 같은 컴파일 오류가 발생합니다.
The method foo(ArrayList<Parent>) in the type ChildClass is not applicable for the arguments (ArrayList<ChildClass>)
다형성 규칙에 따라 수행 할 수 있어야합니다. 권리? 모든 ChildClass는 IS-A 부모입니다. 무슨 문제가있는 것 같습니까?
'static void foo (ArrayList extends Parent> obj) {}'를 대신 입력하십시오. –
감사합니다.하지만 왜 컴파일되지 않았는지에 대한 설명을 원했습니다. – Ekta