This article mainly introduces the analysis of unary operator instances in the Java language. Friends in need can refer to it.
Unary operator, also called single operator, unary operator, unary operator, English name: UnaryOperator.
Description: Accepts a parameter of type T, and the return value type is also T.
Source code:
public interface UnaryOperator<T> extends Function<T, T> { /** * Returns a unary operator that always returns its input argument. * * @param <T> the type of the input and output of the operator * @return a unary operator that always returns its input argument */ static <T> UnaryOperator<T> identity() { return t -> t; } }
Test code:
@Test public void test(){ super.print(UnaryOperator.identity().apply(1));//输出1 super.print(UnaryOperator.identity().apply(false));//输出false super.print(UnaryOperator.identity().apply("string"));//输出string }
Summary
The above is the detailed content of Detailed explanation of unary operators in Java language. For more information, please follow other related articles on the PHP Chinese website!