[Java8] UnaryOperator Functional Interface

Unary operators need only one operand to perform the task or operation.

From Java definition

Represents an operation on single operand that produces a result of the same type as its operand. This is a specialization of Function for the case where the operand the result are of the same type.

Here are some test cases.

   public void testUnaryOperator()
      UnaryOperator<Integer> increment = (n) -> ++n;
      Assertions.assertEquals(Integer.valueOf(2), increment.apply(1));


No comments:

Post a Comment