I'm looking for a preexisting functional interface like Predicate
, but one whose test
method takes no arguments.
Java Predicate Interface. It is a functional interface which represents a predicate (boolean-valued function) of one argument. It is defined in the java.util.function package and contains test() a functional method.
Using the Predicate interface without lambda, that is, as we did with the pre-java 8 sample code has exactly the same limitation that we had previously : verbosity. As other interesting and more advanced advantage, the interface provides additional methods to the test () method to provide a way to create composed predicates.
default Predicate<T> or (Predicate<? super T> other) – This is also a default method, returns a composed predicate that by performing short-circuiting logical OR of current predicate and another predicate. default Predicate<T> negate () – This also a default method, returns a predicate after performing logical negation (!) on the current predicate.
Java 8 Predicate with Examples. A Functional Interface is an Interface which allows only one Abstract method within the Interface scope. There are some predefined functional interface in Java like Predicate, consumer, supplier etc. The return type of a Lambda function (introduced in JDK 1.8) is a also functional interface.
You're looking for BooleanSupplier
.
https://docs.oracle.com/javase/8/docs/api/java/util/function/BooleanSupplier.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With