Function identity example
Description
Function identity returns a function that always returns its input argument.
Syntax
identity
has the following syntax.
static <T> Function<T,T> identity()
Example
The following example shows how to use identity
.
import java.util.function.Function;
//from w w w. jav a2 s. c om
public class Main {
public static void main(String[] args) {
Function<Integer,Integer> id = Function.identity();
System.out.println(id.apply(3));
}
}
The code above generates the following result.
Home »
Java Lambda »
java.util.function Reference »
Java Lambda »
java.util.function Reference »