-2

I was wondering what is the difference between Unary-Operator and Consumer functional interfaces?

Eventually, both of them get a function and apply it to a generic T.

Thank you in advance!

2 Answers2

1

A Consumer is a method that take a parameter of a generic type T and has no return value (void). A UnaryOperator is a method that take a parameter of a generic type T and return a value of the same type (T).

vincendep
  • 528
  • 4
  • 10
1

Unary-Operator functional interface returns some result but Consumer functional interface doesn't https://docs.oracle.com/javase/8/docs/api/java/util/function/Consumer.html https://docs.oracle.com/javase/8/docs/api/java/util/function/UnaryOperator.html

Mark
  • 44
  • 3