Andi Dan wrote:Because we have (addData1 List <? super Dooby> dataList) it means that the list accepts as parameters only (super types of Dooby) or Dooby types. This means that it accepts a Boody (is a super type of Dooby because Dooby extends Boody) type or even a type of Dooby (but is not in the options). Based on this logic i've chosen dataList.add(b).
what do you mean assignable to Dooby... ??? it can be anything that's a super to Dooby or a Dooby, because Dooby IS A (super) no matter what.
"Thus, dataList.add(b); will be invalid because b is not assignable to Dooby. "
--- b is a super for Dooby. I don't see why it cannot be added.
"If you try to take some object out of dataList, that object will be of a class that is either Dooby or a subclass of Dooby and thus it can be assigned to a variable of class Dooby or its superclass.. Thus, t = dataList.get(0) ; is invalid." - don't get it!!!
That's my roommate. He's kinda weird, but he always pays his half of the rent. And he gave me this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton