If I wrote the Predicate
interface, I\'d want to encode in the interface the fact that it\'s just a function that returns a primitive boolean
, like thi
The method in Predicate
returns boolean
. The method in Function
returns Boolean
. They are not the same. Although there is autoboxing, Java methods don't use wrapper classes when primitives would do. Also, there are differences like Boolean
can be null
while boolean
can't.
It's even more different in the case of Consumer
. The method in Consumer
has return type void
, which means it can implicitly return or return using return;
, but the method in Function
must return using return null;
explicitly.