It would be of great help, if someone can point out the problem and possible explanation here.
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) {
}
This throws the following compilation error.
The method foo(ArrayList<Parent>) in the type ChildClass is not applicable for the arguments (ArrayList<ChildClass>)
The rule of Polymorphism should allow me to do it. Right? After all the ChildClass IS-A Parent. What seems to be the problem?