lambda-dev Digest, Vol 21, Issue 4

Rémi Forax forax at univ-mlv.fr
Tue Aug 9 06:33:19 PDT 2011


On 08/09/2011 04:47 AM, 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?
>
>
>>>      * 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
>

You can have a List<I> and try to find a J in it
with I and J two unrelated interfaces but A a class that implements I and J.
so
    A a = new A();
    List<I> listOfI = Arrays.<I>asList(a);
    List<J> listOfJ = Arrays.<J>asList(a);
    assert listOfI.filter(Filters.in(listOfJ)).equals(listOfI);
should compiles.

Rémi




More information about the lambda-dev mailing list