Java Lambda - IntUnaryOperator identity example








IntUnaryOperator identity returns a unary operator that always returns its input argument.

Syntax

identity has the following syntax.

static IntUnaryOperator identity()

Example

The following example shows how to use identity.

import java.util.function.IntUnaryOperator;

public class Main {

  public static void main(String[] args) {
    IntUnaryOperator i = IntUnaryOperator.identity();
    System.out.println(i.compose(i).applyAsInt(2));
  }
}

The code above generates the following result.