identity
is a static method of the LongUnaryOperator
interface that returns a LongUnaryOperator
that always returns the input argument.
static LongUnaryOperator identity()
This method has no parameters.
The method returns a unary operator that always returns its input argument.
import java.util.function.LongUnaryOperator; public class Main { public static void main(String[] args){ LongUnaryOperator identity = LongUnaryOperator.identity(); long arg = 234; System.out.printf("(%s == identity.applyAsLong(%s)) = %s", arg, arg, (arg == identity.applyAsLong(arg))); } }
Line 1: We import the LongUnaryOperator
interface.
Line 6: We define an identity function using the identity()
method.
Line 7: We define a long
called arg
.
Line 8: We check whether arg
and the value returned are equal. We use the applyAsLong()
method by passing arg
as an argument.
RELATED TAGS
CONTRIBUTOR
View all Courses