Chapter 7Being Lazy
In Java we often execute code eagerly. The arguments are evaluated right at the time of method calls, for example. There’s a good reason for that; eager code is easy to write and to think about. But delaying commitments until the last responsible moment is a good agile practice. When executing code, we can gain in performance by being just a little lazy. Eager is simple, but lazy is efficient. But, with lambdas we can easily be lazy and make things simple and efficient at the same time.
Delaying the execution of a function until it’s necessary is a good strategy. However, we still need to figure out how to delay the function invocation, and that can take some work. Paradoxically, laziness often requires effort, and this ...
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