Hey guys,
I'm really confused about that.
Plese look at explanation extracted from K&B Study Guide for
Java 5 about <? super ...> syntax :
Chapter 7, page 594
Now what you've said in this line
public void addAnimal(List<? super Dog> animals)
is essentially, "Hey compiler, please accept any List with a generic type that is of type Dog, or a
supertype of Dog. Nothing lower in the inheritance tree can come in, but anything higher than Dog is OK."
But after trying a few Java codes, I could realize that is happening the opposite. Anything lower in the hierarchy is allowed but anything higher is not.
Please check out the following code :
As per above code you can see that with super I cannot add Dog's parent class but anything lower in the hierarchy is allowed.
After that I'm really confused because until now I think I was thinking in wrong way.
Could P L E A S E explain that.
Any comment would be H I G H L Y appreciated.