On pages 210 - 211 in the book 'Certified Associate Java SE 8 Programmer I' by Jeanne Boyarsky and Scott Selikoff, there is a code sample that demonstrates lambda expressions. It basically prints out the names of animals based on a boolean of whether they can swim or hop:
On page 211, the book says, "This code uses a concept called deferred execution. Deferred execution means that code is specified now but will run later. In this case, later is when the print() method calls it."
I don't understand. The lambda print method on lines 16 and 17 seem to be listed in the main method just like any method calls would. So what difference is 'deferred execution' supposed to make here?
What it means is that the calls to canHop() and canSwim() are deferred. Normally when an expression contains a nested method call, that method call is evaluated immediately. In this case however, canHop() and canSwim() are called when print calls test().
Here's another example:
Calling person.printName() could result in an output like this:
So even though getFirstName() appears before getLastName() on line 12, getLastName() is executed first. We say execution of getFirstName() has been deferred.
Line 6 isn't a statement; it might be if it had a second ; at the end of it in which case it might become a kind of expression statement. Please check carefully what the book says, to verify where the actual error is.
You have to be odd to be #1 - Seuss. An odd little ad: