Java : BooleanSupplier with Examples
BooleanSupplier (Java SE 21 & JDK 21) with Examples.
You will find code examples on most BooleanSupplier methods.
Summary
Represents a supplier of boolean-valued results. This is the boolean-producing primitive specialization of Supplier.
public void test(BooleanSupplier supplier) {
System.out.println("getAsBoolean = " + supplier.getAsBoolean());
}
final var supplier = new BooleanSupplier() {
@Override
public boolean getAsBoolean() {
return false;
}
};
test(supplier); // getAsBoolean = false
// An example with a lambda expression.
test(() -> true); // getAsBoolean = true
Methods
boolean getAsBoolean ()
Gets a result.
public void test(BooleanSupplier supplier) {
System.out.println("getAsBoolean = " + supplier.getAsBoolean());
}
final var supplier = new BooleanSupplier() {
@Override
public boolean getAsBoolean() {
return false;
}
};
test(supplier); // getAsBoolean = false
// An example with a lambda expression.
test(() -> true); // getAsBoolean = true
Related posts
- API Examples
- @FunctionalInterface
- BiConsumer
- BiFunction
- BiPredicate
- Consumer
- DoubleConsumer
- DoubleFunction
- DoublePredicate
- DoubleSupplier
- Function
- IntConsumer
- IntFunction
- IntPredicate
- IntSupplier
- LongConsumer
- LongFunction
- LongPredicate
- LongSupplier
- Predicate
- Runnable
- Supplier
- ToDoubleFunction
- ToIntFunction
- ToLongFunction