Hi ayush, dan and himai. From what all I have read in the posts from you guys is that if extends wild card is used it does not let you add anything. Not just <? extends Object> but something like <? extends Animal>. Also I have checked out other wild cards in K&B text.
<?> <? extends XYZ><? super XYZ><Object>
Case1: <? extends XYZ> doesn't add anything from within method!
Case 2: <?> doesn't add anything from within method!
So can I safely understand it to be a rule that <? extends XYZ> and <?> as a method parameter won't allow anything to be added from within that method ass illustrated above?
However, for <? super XYX> and <Object> it's even more peculiar.
Case 3: <? super XYZ>
it adds Dog object but not Animal object. It should right? In the program Dog extends Animal! A partial result.
And if <? super Animal> is used, it adds both from within the method without any error! It shouldn't add Dog if <? super Animal> used right since Dog is subclass! What's the pattern or rule that I can understand here?
Case 4: <Object>
For the above program two things are happening. If I insert a type during instantiation (Dog or Animal) it gives compiler error saying "Object cannot be applied to Animal or Dog" and points to
met(l1).
But if I remove the type during instantiation, all works fine!
Why this confusing thing is happening! I read up K&B but didn't find any such detailed explanation or if there I couldn't pinpoint
Could I get help on each case please? Thanks again guys.