[concurrency-interest] Collection.contains(E)

Eamonn McManus Eamonn.McManus at Sun.COM
Tue Apr 17 04:09:54 EDT 2007


Martin Buchholz wrote:
> 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:
>   

This is basically the same argument as for why these methods in 
Collection<E> take a parameter of type Object or Collection<?> rather 
than E or Collection<? extends E>. It's a good argument, though its 
extension to null elements is perhaps less convincing.

Éamonn McManus   JMX Spec Lead   http://weblogs.java.net/blog/emcmanus/



Martin Buchholz wrote:
> 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
> s.removeAll(p)
> 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.
>
> Martin
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>   



More information about the Concurrency-interest mailing list