Java : BooleanSupplier with Examples
BooleanSupplier (Java SE 21 & JDK 21) with Examples.
You will find code examples on most BooleanSupplier methods.
Summary
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 ()
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