Thank you very much.
So I can define the reference with the <? super> so that the actual collection type (right hand side) can be left hand side or its super type.. but when I add, I can only add whatever I defined on the right hand side.
but any particular use of this?
I know the use super in a method argument, so I can 'add' any supertype of the reference type safely, but why define a reference in this way?
If for example, I say,
But I can only add Animal objects into this, and I even cannot safely call Dog methods on the items inside the dog list.
SO what purpose does this serve?
Isn't this risky? because at compile time, dog list can be a list of Dogs or Animals.
But I cannot invoke Dog methods on the items inside dog list. Because the items can be Dogs or Animals?
What am I missing here.
Thank you.