Why does this Java 8 lambda fail to compile?

Your lambda needs to be congruent with BiConsumer<String, String>. If you refer to JLS #15.27.3 (Type of a Lambda):

A lambda expression is congruent with a function type if all of the following are true:

  • […]
  • If the function type’s result is void, the lambda body is either a statement expression (ยง14.8) or a void-compatible block.

So the lambda must either be a statement expression or a void compatible block:

Leave a Comment