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!
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!
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).
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