While trying to play with method references, came across a situation where concat method can be used as a BiFunction, as I understand BiFunction apply method requires 2 input arguments and produces a result. Whereas, concat method takes 1 input argument and returns the concatenated string with this value.
Sample code:
public class Test {
public static void main(String[] args) {
Test t = new Test();
String str1 = "Hello";
String str2 = "Workld";
System.out.println(t.stringManipulator(str1, str2, String::concat));
System.out.println(str1);
System.out.println(str2);
}
private String stringManipulator(String inputStr, String inputStr2, BiFunction<String, String, String> function) {
return function.apply(inputStr, inputStr2);
}
}
Output
HelloWorkld
Hello
Workld
Can someone help me understand what happened here?