commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Neidhart (JIRA)" <>
Subject [jira] [Commented] (COLLECTIONS-537) PredicateUtils (all|any)Predicate type misbehaviour Array vs. Collection
Date Fri, 26 Dec 2014 13:30:13 GMT


Thomas Neidhart commented on COLLECTIONS-537:

Yes indeed, the correct signature should be:

    Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>>

This change will require some more changes in other places too for sake of consistency.
The test case to demonstrate the change:

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections4.Predicate;
import org.apache.commons.collections4.PredicateUtils;

public class MyTest {

    public static class A {
        int val;
        public A(int val) {
            this.val = val;
        public String toString() {
            return "A";
    public static class B extends A {
        public B(int val) {
        public String toString() {
            return "B";
    public static class MyPredicate implements Predicate<A> {

        private int eval;
        public MyPredicate(int eval) {
            this.eval = eval;

        public boolean evaluate(A object) {
            return object.val < eval;

    public static void main(String[] args) {
        MyPredicate p1 = new MyPredicate(10);
        MyPredicate p2 = new MyPredicate(20);

        Predicate<B> anyPredicate = PredicateUtils.anyPredicate(p1, p2);
        System.out.println(anyPredicate.evaluate(new B(10)));
        List<Predicate<A>> list = new ArrayList<Predicate<A>>();
        Predicate<B> anyPredicate2 = PredicateUtils.anyPredicate(list);
        System.out.println(anyPredicate2.evaluate(new B(10)));

> PredicateUtils (all|any)Predicate type misbehaviour Array vs. Collection
> ------------------------------------------------------------------------
>                 Key: COLLECTIONS-537
>                 URL:
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Functor
>    Affects Versions: 4.0
>            Reporter: Frank Jakop
> Migrating from collections-generic to collections4 we encountered a type problem with
PredicateUtils. When you look at the method anyPredicate(), the signature with array is typed
with "Predicate<? super T>" whereas the signature with Collection is typed "? extends
Predicate<T>", so the both methods are not equivalent.
> We think both methods should have the same types, so it would not break compatibility
with a lot of legacy code.

This message was sent by Atlassian JIRA

View raw message