Vierda Mila wrote:Hi N path,
one rule you have to remember here that polymorphism is not apply for generic type.
if you provide as per below it will result compile error :
Cage<Animal> cg1 = new Cage<Dog>();
but these example is ok :
Cage <Animal> cg1 = new Cage <Animal>();
Cage<? extends Animal cg1 = new Cage <Dog>();
please check this one for further information
regards,
-Vierda-
Thanks for your reply Vierda.
But what exactly does the syntax mean then? If it is to be explained in simple english..
As in,
Cage<Animal> cg = new Cage<Animal>();
Cage<? extends Dog> cg1 = new Cage<Dog>();
According to this syntax, cg can contain an object of Animal class. Then what does the type in RHS signify?
In the first case, the type in LHS and RHS is the same. Why is it not the same in the second case? Why can't we write the following
Cage<? extends Dog> cg1 = new Cage<? extends Dog>();
This is a little tough to explain!

But i hope you understand! All i mean to ask it, what do the types on each side indicate in plain English?