Home > Java > javaTutorial > Detailed explanation of unary operators in Java language

Detailed explanation of unary operators in Java language

黄舟
Release: 2017-09-21 10:43:48
Original
2566 people have browsed it

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;
  }
}
Copy after login

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  }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template