Friday, July 24, 2015

Java Lambda - IntToLongFunction Functional Interface

IntToLongFunction Functional Interface

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

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



applyAsLong() method

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

IntToLongFunction i = (x) -> (long) x + x;
System.out.println(i.applyAsLong(Integer.MAX_VALUE)); //Outputs 4294967294

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