Effective Java! Prefer Method References to Lambdas

Kyle Carter
2 min readJun 8, 2021

One of the main benefits of lambdas is the conciseness of the code versus the use of an anonymous class. Even so, there are times that even lambdas end up with unnecessary boilerplate. In these cases we can often make use of method references which is something we even saw used in our last post.

Method references are really just that, a reference to a method that allows us to skip the boilerplate of simply passing parameters from one place to another. Let’s look at an extremely simple example:

IntStream.of(1,2,3).redu

--

--

Kyle Carter

I'm a software architect that has a passion for software design and sharing with those around me.