Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator
identity

Identity method of the LongUnaryOperator interface in Java

abhilash

identity is a static method of the LongUnaryOperator interface that returns a LongUnaryOperator that always returns the input argument.

Syntax

static LongUnaryOperator identity()

Parameters

This method has no parameters.

Return value

The method returns a unary operator that always returns its input argument.

Code

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)));
    }
}
Implementation of the "identity" method

Explanation

  • 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

java
communitycreator
identity
RELATED COURSES

View all Courses

Keep Exploring