lets say we a Predicate
and a Function
-Interface:
Function<String, String> function = null;
Predicate<String> predicate = null;
Now I want to give the Predicate
-Interface a method reference where the return type is a boolean
and in our case the parameter a string. But why the following method reference seems to be right:
Predicate<String> predicate = String::isEmpty;
The isEmpty
-method has no String-Parameter,although the Predicate
-Interface requires a String-Parameter. Why it is still right? Am I missing something?
Another Example: The Function interface returns in our case a String and takes a String as parameter. But the following method reference seems to be wrong:
Function<String, String> function = String::concat; //wrong
The Concat-Method has a String as Parameter and returns a String. Why its wrong?
Hopefully somebody can explain it to me.