lambda-dev Digest, Vol 21, Issue 4

Mike Duigou mike.duigou at oracle.com
Mon Aug 8 19:47:50 PDT 2011


On August 6, 2011 09:17:29 PDT , Rémi Forax <forax at univ-mlv.fr> wrote:

> On 08/06/2011 01:13 PM, Steven Simpson wrote:
>> On 05/08/11 02:09, mike.duigou at oracle.com wrote:
>>> + src/share/classes/java/util/functions/Predicates.java
>> http://hg.openjdk.java.net/lambda/lambda/jdk/file/38969e64b60e/src/share/classes/java/util/functions/Predicates.java
>> 
>>   162      public static<T>   Predicate<T>   contains(Collection<? extends T>   target) {
>>   163          return #{T t ->   target.contains(t)};
>>   164      }
>> 
>> A couple of points:
>> 
>>     * Shouldn't that be "containedBy", "containedIn", "in", or similar?

What's wrong with contains?


>>     * target could be declared Collection<?>, right?
>> 
>> Cheers,
>> 
>> Steven
> 
> Right! Collection.contains takes an Object as parameter,
> so Predicate.contains should work with any collections.

Collections.contains takes Object for primarily backwards compatibility reasons. There's no reason in a new interface not to restrict to a tighter definition. Is there a good reason to take Object rather than T? All of the values which are going to be passed to the eval() will be of type T so it seemed reasonable to have the collection restricted to T as well.

Mike


More information about the lambda-dev mailing list