lambda-dev Digest, Vol 21, Issue 4

Dan Smith daniel.smith at oracle.com
Wed Aug 10 10:55:36 PDT 2011


On Aug 9, 2011, at 4:15 AM, Steven Simpson wrote:

> On 09/08/11 03:47, Mike Duigou wrote:
>> 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?
> 
> Obviously, this is just a matter of English grammar, but 
> Predicate.contains(myList) looks like a predicate that matches an object 
> containing myList, not a predicate matching an object contained in myList.

In fact, a reasonable definition of Predicate might look like:

interface Predicate<T> {
  boolean contains(T arg);
}

In this case, there's no need for a conversion utility at all, because Collection<T> can directly implement Predicate<Object>.

Alternately, to clarify the grammatical intent of the method in question, maybe "collectionContains" (that is, we don't mean "containsCollection").

FWIW, note that this method is sort of redundant, since the same thing can be accomplished with "target#contains".

—Dan



More information about the lambda-dev mailing list