Saturday, July 25, 2015

Java Lambda - LongToDoubleFunction Functional Interface

LongToDoubleFunction Functional Interface

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

LongToDoubleFunction interface is long to double primitive specialization of Function interface.



applyAsDouble() method

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

LongToDoubleFunction longToDoubleFunc = (val) -> (double) val + val;
System.out.println(longToDoubleFunc.applyAsDouble(Long.MAX_VALUE));
Outputs:
1.8446744073709552E19

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