[concurrency-interest] Collection.contains(E)

Martin Buchholz Martin.Buchholz at Sun.COM
Tue Apr 17 01:26:29 EDT 2007

Here is an argument for why you might want query operations
like contains(E) to *not* throw when the query object would
not be permitted as an element:

contains(E) is used to build higher-level operations like
removeAll and retainAll.

if s is a set of students at a university, and
if p is a set of professors at a university,
then these sets need not be disjoint, and so
is an operation that makes sense, and should not be
prohibited, even when *inserting* an element of the
wrong type should be.

So contains(E) should generally never throw exceptions
based on the unsuitability of its argument.


More information about the Concurrency-interest mailing list