Thursday, July 23, 2015

Java Lambda - IntSupplier Functional Interface

IntSupplier Functional Interface

IntSupplier interface represents a supplier of int valued results. This interface is int data type primitive specialization for Supplier interface. Previously we had discussed Supplier, DoubleSupplier and BooleanSupplier, and LongSupplier.

IntSupplier interface does not have any default methods.

getAsInt() method

int getAsInt();
This method returns the result. Return type is int. Let us write simple example for IntSupplier which will return MAX and MIN value of Integer class.

IntSupplier supplyMin = () -> Integer.MIN_VALUE;
System.out.println("Min is " + supplyMin.getAsInt());

IntSupplier supplyMax = () -> Integer.MAX_VALUE;
System.out.println("Max is " + supplyMax.getAsInt());

Min is -2147483648
Max is 2147483647

That’s all on IntSupplier 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