In Java, identity
is a static method of the IntUnaryOperator
interface, used to return an IntUnaryOperator
that always returns the input argument.
static IntUnaryOperator identity()
The method takes no parameters.
The method returns an IntUnaryOperator
that always returns its input argument.
import java.util.function.IntUnaryOperator;public class Main {public static void main(String[] args){IntUnaryOperator identity = IntUnaryOperator.identity();int arg = 343;int arg1= 12;System.out.printf("(%s == identity.applyAsInt(%s)) = %s \n", arg1, arg1, (arg1 == identity.applyAsInt(arg1)));System.out.printf("(%s == identity.applyAsInt(%s)) = %s \n", arg1, arg, (arg1 == identity.applyAsInt(arg)));System.out.printf("(%s == identity.applyAsInt(%s)) = %s \n", arg, arg1, (arg == identity.applyAsInt(arg1)));System.out.printf("(%s == identity.applyAsInt(%s)) = %s", arg, arg, (arg == identity.applyAsInt(arg)));}}
IntUnaryOperator
interface.identity()
method to define an identity function.arg
and arg1
.applyAsInt()
to check whether the integer values arg
, arg1
, and the value returned are equal.