February 2014
Intermediate to advanced
160 pages
4h 59m
English
In the previous section we delayed creation of heavyweight objects to make code execution faster. We’ll explore that further in this section to delay running methods, and use that approach to improve our designs. The main objective is to reduce the execution of code to the bare minimum—especially the expensive code—and speed up the execution.
Java already uses lazy execution when evaluating logical operations. For example, in fn1() || fn2(), the call fn2 is never performed if fn1 returns a boolean true. Likewise, if we replace the || with &&, the call to fn2 never happens if fn1 returns a boolean false. Programs benefit from this short-circuiting; we avoid unnecessary evaluation of expressions or functions, and that can help ...