A return value of a method call may always be discarded. So, since map.put is such a call, you can use it as if it were a void method. Just like you can do a single statement: 'map.put(k, v);' where you also discard the return value.
This doesn't work:
There are three kinds of actuaries: those who can count, and those who can't.
It's a reasonable assumption, especially if you haven't seen examples where the returned value is ignored. And even if you had, it isn't obvious that they can also be ignored in that lambda-expression context. But yeah, there's actually a rule somewhere in the Java language spec which says that methods' return values can be ignored.
The Java Language Specification wrote:An expression statement or lambda body that is a method invocation may also invoke a method that produces a result; in this case the value returned by the method is quietly discarded.
Note: emphasis is mine.
Let nothing stop you! Not even this tiny ad:
a bit of art, as a gift, that will fit in a stocking