In an earlier blog post ("Deferred Execution with Java's Supplier"), I referenced Cay Horstmann's statement in the book "Java SE8 for the Really Impatient," regarding lambda expressions, saying that "the point of all lambdas is deferred execution." Horstmann wrote an article called "Lambda Expressions in Java 8" for Dr. Dobb's magazine in its final year in which he wrote a similar statement using different terminology, "A lambda expression is a block of code that you can pass around so that it can be executed later, just once or multiple times."
In my previous post, I looked at how the standard functional interfaceSupplier is used with lambda expressions in the JDK to support deferred execution for cases. This happens when a single value is "supplied only when necessary" and without any argument passed to it. In this post, I focus on JDK-provided examples of using the Consumer standard functional interface to "consume" or "process" a particular code block. While the Supplier accepts no arguments and returns exactly one response, the Consumeraccepts one or more arguments and returns no response. The method invoked on a Supplier is the get()method. It is the accept(T) method for a Consumer. By definition, the Consumer is expected to have "side effects" as it "consumes" the provided code block.
from DZone.com Feed https://ift.tt/2lEYZ1q
No comments:
Post a Comment