Could you please explain me why java.util.Stream method void forEach(Consumer<? super T> action) is aplicable for public StringBuilder append(String str) method of StringBuilder class? So this becomes legal:
As for me, append method returns reference to StringBuilder but forEach expects Comsumer which means void return type.messages.stream().forEach(s->s.append("helloworld"));
If we dig deeper then we will come to the following legal code:
Code: Select all
...
Consumer<StringBuilder> cm = s -> s.append("helloworld");
Function<StringBuilder, StringBuilder> r3 = s -> s.append("helloworld");
...
Best regards,
Aleksei