Thursday, July 23, 2015

Java Lambda - LongSupplier Functional Interface

LongSupplier Functional Interface

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

LongSupplier interface does not have any default methods.

getAsLong() method

long getAsLong();
This method returns the result. Return type is long. Let us write simple example for LongSupplier which will return MAX and MIN value of Long class.

LongSupplier supplyMin = () -> Long.MIN_VALUE;
System.out.println("Min is " + supplyMin.getAsLong());

LongSupplier supplyMax = () -> Long.MAX_VALUE;
System.out.println("Max is " + supplyMax.getAsLong());

Min is -9223372036854775808
Max is 9223372036854775807

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