Guava Predicates cannot be used out of the box as a filter using the java 8 streaming API.
For example, this is not possible:
Number first = numbers.stream() .filter( com.google.common.base.Predicates.instanceOf(Double.class))) .findFirst() .get();
As soon as possible when the guava predicate is converted to a java 8 predicate, for example:
public static <T> Predicate<T> toJava8(com.google.common.base.Predicate<T> guavaPredicate) { return (e -> guavaPredicate.apply(e)); } Number first = numbers.stream() .filter( toJava8( instanceOf(Double.class))) .findFirst() .get();
QUESTION: Is there a more elegant way to reuse guava Predicates in java 8?
source share