String::concat
is a reference to the concat()
method of the String class.
A BiFunction
is a functional interface with a single method apply
that accepts two parameters (the first of type T
and the second of type U
), and returns a result of type R
(in other words, the interface BiFunction<T,U,R>
has a method R apply(T t, U u)
).
map.merge
expects a BiFunction<? super V,? super V,? extends V>
as the third parameter, where V
is the value of the Map
. If you have a Map
with a String
value, you can use any method that accepts two String
parameters and returns a String
.
String::concat
satisfies these requirements, and that's why it can be used in map.merge
.
The reason it satisfies these requirements requires an explanation :
The signature of String::concat
is public String concat(String str)
.
This can be seen as a function with two parameters of type String (this
, the instance for which this method is called, and the str
parameter) and a result of type String.