Does Collection <? extends myObject>
mean that I can put in the Collection both myObject and objects that extend myObject?
Not really - it means that the collection is a collection of some specific type that extends myObject
. To take a clearer example, if you have a Collection<? extends Number>
it could be a Collection<Integer>
or maybe a Collection<Double>
or maybe a Collection<Number>
but you don't know which.
As a consequence you can't add anything to that collection because you don't know what its generic type is. However if you get an element from that collection you can be assured that it is a Number
.
List<? extends Number> c = getList();
Number n = c.get(0); //ok
c.add(1); //not ok, c could well be a List<BigDecimal>, we don't know