liveBook · Manning

Lambda

As explained in 100 Java Mistakes and How to Avoid Them

A lambda expression is an anonymous Java function-like expression that provides an implementation compatible with a functional interface.

A lambda expression is an anonymous Java function-like expression that supplies an implementation compatible with a functional interface. Its parameter list makes argument flow explicit, including arguments that the body ignores. section 2.13

Avoiding an accidental constructor binding

In contents.computeIfAbsent(fileName, StringBuilder::new), the method reference receives the map key and can select StringBuilder(String), producing content such as numbers.txt3.1415. Convert it to s -> new StringBuilder() when the key should be ignored.

Use lambda syntax when an overloaded method or constructor makes a compact method reference ambiguous. Naming the parameter and writing the target call exposes which declaration receives it; an IDE conversion can help reveal the binding. section 2.13 section 2.15

How 100 Java Mistakes and How to Avoid Them covers it

How deep it goes
Explains parameter flow, ignored arguments, overload ambiguity, and constructor binding through focused Java examples, without runtime internals.
Examples
Uses Integer.sum, StringBuilder factories, map initialization, and Arrays.setAll to contrast method references with explicit lambdas.
What it assumes
Assumes familiarity with Java methods, constructors, maps, and functional interfaces while demonstrating lambda parameter handling explicitly.
What you can do after
Diagnose/debug with lambda conversion when a method reference selects an unintended overload or constructor.
How it connects
Connects lambda expressions with functional interfaces, method references, overloaded constructors, and computeIfAbsent.

Also explained in

Compare how 18 books explain lambda →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 Java Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.