identity
is a static method of the Function
interface that always returns the input argument.
static <T> Function<T, T> identity()
The method has no parameters.
The method returns a function that always returns its input argument.
import java.util.function.Function;public class Main {public static void main(String[] args){Function<Integer, Integer> identity = Function.identity();int arg = 1;System.out.printf("(%s == identity.apply(%s)) = %s", arg, arg, (arg == identity.apply(arg)));}}
Function
interface.identity()
method.arg
.arg
and the value returned are equal. We do this by using the apply()
method passing arg
as an argument are equal.