What is the LongToDoubleFunction functional interface in Java?
LongToDoubleFunction is a functional interface that accepts one argument of type long and returns a result of type double. The interface contains one method, applyAsDouble.
The LongToDoubleFunction interface is defined in the java.util.function package. To import the LongToDoubleFunction interface, use the following import statement.
import java.util.function.LongToDoubleFunction;
applyAsDouble(long value)
The applyAsDouble method applies the function to the given argument of type long and produces a result of type double. This is the functional method of the interface.
Syntax
double applyAsDouble(long value)
Parameters
long value: The function argument of typelong.
Return value
The method returns the function result of type double.
Code
import java.util.function.LongToDoubleFunction;public class Main{public static void main(String[] args) {// Implementation of LongToDoubleFunction interface that returns square of the long valueLongToDoubleFunction longToDoubleFunction = value -> value * value;long value = 34;// calling applyAsDouble method of LongToDoubleFunctionSystem.out.println(longToDoubleFunction.applyAsDouble(value));}}
In the code above, we create an implementation of the LongToDoubleFunction interface that accepts a long argument and returns the square of the argument as a double value.