Paul Clapham wrote:So I hovered the mouse over various parts of the reduce member's parameters and it interprets them as
Nyeng wrote:The three-parameter reduce() stream operation/method requires the following, when the method is invoked: The type of the first, identity argument passed to the method must be the same as the (single) type of the BinaryOperator lambda passed as the third, combiner argument to the method as well as the type of the first parameter and return type of the BiFunction lambda passed as the second, accumulator argument to the method. In the particular case of the code for the three-parameter method above (on lines 5 through 7), the type of these types that must be the same is the String type.
Since the stream items in the code shown are char types, I expect that the type, of the first parameter of the BiFunction lambda passed as the second, accumulator argument to the three-parameter method, should be Character and not String. However, it appears like the compiler is okay with the three-parameter method having the type of this first parameter of the BiFunction lambda being String, rather than Character. I am unable to see why the compiler is okay with this, even though I do understand why it would be okay with the (single) type of the BinaryOperator lambda passed as the third, combiner argument to the method to be String.
Piet Souris wrote:You go from characters to String using the reduce-method.