Monday, July 13, 2015

Java Lambda - BooleanSupplier Functional Interface

BooleanSupplier Functional Interface

BooleanSupplier Interface is supplier of boolean valued results. BooleanSupplier is primitive specialization of Supplier for boolean type.


BooleanSupplier Interface Declaration

public interface BooleanSupplier

BooleanSupplier interface is a primitive specialization of Supplier for boolean type.
  


boolean getAsBoolean();

This method returns the result.

BooleanSupplier bool = () -> false;
System.out.println(bool.getAsBoolean()); //Outputs false

bool = () -> true;
System.out.println(bool.getAsBoolean()); //Outputs true

String s1 = "ABC";
String s2 = "ABC";
BooleanSupplier stringEquals = () -> s1.equals(s2);
System.out.println(stringEquals.getAsBoolean()); //Outputs true
           
int x = 10;
int y = 20;
BooleanSupplier intCompare = () -> x > y;
System.out.println(intCompare.getAsBoolean()); //Outputs false



That’s all on BooleanSupplier Interface.

Read about important java.util.function package’s interface here. Consumer, Function, Supplier, BinaryOperator & Predicate Functional Interfaces. I have also written on High Order functions using Function functional interface.




No comments:

Post a Comment

Ads Inside Post