Java 8 Predicate instead of Guava Predicate

1,096 views
Skip to first unread message

Jan Zarnikov

unread,
May 4, 2015, 8:22:27 AM5/4/15
to testfx-...@googlegroups.com
Currently the lookup and verification API uses com.google.common.base.Predicate. The problem is that you can't specify these predicates with a lambda or method reference because Guava-Predicate is not a @FunctionalInterface.

I think it would make sense to switch to normal Java 8 java.util.function.Predicate. This would simplify the assertions for the users and remove an unnecessary dependency from the API. 

Same goes for com.google.common.base.Function and com.google.common.base.Optional (both used in NodeQuery). 

Benjamin Gudehus

unread,
May 4, 2015, 8:52:04 AM5/4/15
to Jan Zarnikov, testfx-...@googlegroups.com
Hi Jan,

a migration from the Guava API to the Java 8 API for Predicate, Function and Optional makes sense. We also use Preconditions, Stopwatch, SettableFuture, Ordering and Immutable{List,Set} from Guava.

I checked the master branch in Guava and they didn't add @FunctionalInterface to Predicate et. al. However at least with IntelliJ everything works fine with Guava Predicates and Lambdas.

SSCCE:

~~~java
import com.google.common.base.Function;
import com.google.common.base.Predicate;

public class GuavaFunctionalInterface {
    public static void main(String[] args) {
        predicate((text) -> text.length() > 10);
        function((text) -> text.length() > 10);
    }

    public static void predicate(Predicate<String> stringPredicate) {}
    public static void function(Function<String, Boolean> stringBooleanFunction) {}
}
~~~

--Benjamin

--
You received this message because you are subscribed to the Google Groups "TestFX" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testfx-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages