public class AnimalDoctorGenric2
{
public static void main(String[] args)
{
List<Animal> mylist = new ArrayList<Animal>();
mylist is not an ArrayList, but a List. The JVM knows that an ArrayList is a List but not all List's are ArrayLists so you can do List<anyList> yourList = new ArrayList<anArrayList> but you can`t do ArrayList<anArrayList> youArrayList = new List<yourList>...
so if you need your List to came an ArrayList again try that:
ArrayList<Animal> anotherList;
anotherList = (ArrayList)myList;
Dog d = new Dog();
Cat c = new Cat();
Animal a = new Animal();
mylist.add(new Cat("Black"));
mylist.add(new Dog("Doverman"));
for(Object o : mylist)
System.out.println(o);
AnimalDoctorGenric2 ad = new AnimalDoctorGenric2();
//ad.calldoctor(d);
or try it
ad.calldoctor
((ArrayList)mylist);
//ad.calldoctor(c);
}
//>>>??? Question
public void calldoctor(List<Animal> animal)//Instead of List if i use
{ //ArrayList its giving me
//compiletime error
//eventhough i am passing Animal
//type reference....??
animal.add(new Dog("Germanshephered"));
}
}
Sometimes programming means