![]() |
VOOZH | about |
The UnaryOperator<T> interface is a part of the java.util.function package introduced in Java 8. It represents a function that takes only one argument, performs an operation on it, and returns a result of the same type. In simple words, input type and return type both remain the same in UnaryOperator.
25
Explanation:
UnaryOperator<T> operatorName = value -> operation;
T : Represents both the input type and return type.
The UnaryOperator interface inherits methods from Function<T, T> interface.
The apply() method performs the operation defined in the lambda expression and returns the result.
Syntax:
T apply(T t)
27
The andThen() method first executes the current function and then executes the next function.
Syntax:
default <V> Function<T, V>andThen(Function<? super R, ? extends V> after)
25
The compose() method first executes the given function and then executes the current function.
Syntax:
default <V> Function<V, R>compose(Function<? super V, ? extends T> before)
30
This method returns a UnaryOperator that simply returns the same value passed to it. It does not perform any modification.
Syntax:
static <T> UnaryOperator<T> identity()
Java
| Method | Execution Order |
|---|---|
| andThen() | Current function -> Next function |
| compose() | Given function -> Current function |