Prefer Method References
Short lambda expressions are great, but they still require human eyes to parse through them to find out what they’re doing. If we can replace a lambda expression, where possible, with a method reference, the code becomes ultimately more readable and concise—see Using Method References. The method names make the overall functional pipeline clearer from the context than the corresponding lambdas. Using method references makes it easier to look at the code and be confident about its intent, and takes less mental effort to maintain the code.
Prefer method references over lambda expressions where it’s possible to replace the latter with the former. The following code uses lambda expressions in each stage of the Stream
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access