Saturday, July 25, 2015

Java Lambda - LongToIntFunction Functional Interface

LongToIntFunction Functional Interface

LongToIntFunction interface represents a function that accepts an long valued argument and produces a int valued result. Previously we have discussed Function interface, higher order functions, DoubleFunction. I would highly recommend you to read the above interfaces.

LongToIntFunction interface is long to int primitive specialization for Function interface.

applyAsint() method

int applyAsInt(long value);
This method accepts long as input and returns int as result. Let us take simple example of this interface.

LongToIntFunction longToIntFunc = (val) -> (int) val;
System.out.println(longToIntFunc.applyAsInt(Long.MAX_VALUE)); //Outputs -1

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