Possible Duplicate:
IsList<Dog>
a subclass ofList<Animal>
? Why aren't Java's generics implicitly polymorphic?
I have a List of class Dogs which extends Animals and have a List of the following type.
ArrayList<Animals> animal = new ArrayList<Animals>();
Now I have another class, Puppy, which extends Dogs.
And have a List<Puppy> puppy = new ArrayList<Puppy>();
Now I want to cast list animal
to puppy
. Is it possible to do directly?
I can do it as below.
for (Animals ani: animal){
puppy.add((Puppy) ani)
}
But I want a direct casting solution. Is it possible?