The collection types only use their generic type E
in cases where it must match in order for the operation to be legal. If you have a list of strings then clearly something like add
can only make sense when passed a string.
But for operations like contains
it's different - it is perfectly legal to ask whether a list of strings contains a particular Integer
, for example. The answer will always be no, but that doesn't make it an error to ask the question.