This content has been marked as final. Show 5 replies
This was discussed extensively a few weeks ago if I recall correctly.
Search the forums and you'll find plenty of answers.
user5434016 wrote:Hint: have a look at Collection.remove().
Why not use removeAll(Collection<? extends E> c) ?
And if these confuse you, wait till you get to Map :-).
user5434016 wrote:Because you can only add E to a Collection<E>
Why does it use <? extends E>
and <?>Because there's no harm in trying to remove() something that could never be there in the first place. (Actually there's a more technical reason, and it might even be that it has to be <?> in this case, but I don't remember the details and am not interested enough to try to find them again.)
The reason is that the Collection is only specified to contain items that compare-equal to the items to be removed, and that for backward compatibility reasons it was decided not to tighten this up to require <E>.
As a note there is a generics forum.