I'm not getting any error. What error are you referring to?
Joined: Oct 04, 2006
try to add
Joined: Oct 17, 2006
You can not add an object of type A to the list. You are allowed to add just objects of type B or subtypes of B to the list. Imagine that you instantiate your collection with new LinkedList<B>(). What would happen if you were allowed to add an object of type A to it?
Yes, you are right. Your list (List<? super B> can take any list with the type being B or supertype of B. Your list could be LinkedList<B> or LinkedList<A>. But when you try to add something to the list, the type of the object that you add must pass the IS-A B relationship. Think what would happen if you added an object of type A and instantiated your list: List<? super B> l = new LinkedList<B>(). If you were allowed to add objects of type A to the list, you'd get a list of type B that would contain objects of type A. This is Not ok.