IntToLongFunction
is a functional interface that accepts one argument of type int
and returns a result of type long
. The interface contains one method, applyAsLong
.
The IntToLongFunction
interface is defined in the java.util.function
package. To import the IntToLongFunction
interface, use the following import statement.
import java.util.function.IntToLongFunction;
applyAsLong(int value)
methodThe applyAsLong(int value)
method applies the function to the given argument of type int
and produces a result of type long
. This is the functional method of the interface.
long applyAsLong(int value)
int value
: the function argument of type int
.The method returns the function result of type long
.
import java.util.function.IntToLongFunction;public class Main{public static void main(String[] args) {// Implementation of IntToLongFunction interface that returns square of the int valueIntToLongFunction intToLongFunction = value -> (long) value * value;int value = 34;// calling applyAsLong method of IntToLongFunctionSystem.out.println(intToLongFunction.applyAsLong(value));}}
In the code above, we create an implementation of the IntToLongFunction
interface that accepts an int
argument and returns the square of the argument as a long
value.