Java Reference
In-Depth Information
This JavaFX application produces a simple application that looks like Figure 2-1 .
When you press the button, the ActionListener, which is a lambda expression, is in-
voked.
Figure 2-1 . Lambda expression as a button action listener
How It Works
Lambda expressions are one of the new features of Java 8 that will have a tremendous
impact on productivity and business logic. Lambda expressions are anonymous blocks
of code that accept zero or more parameters, encapsulate a series of statements or an
expression, and return a result. They are analogous to closures from other languages,
being anonymous functions that can be passed into other code as needed.
The syntax of a lambda expression includes an argument list, a new character to the
language known as the “arrow token” ( -> ), and a body. The following model repres-
ents the structure of a lambda expression:
(argument list) -> { body }
The argument list for a lambda expression can include zero or more arguments. If
there are no arguments, then an empty set of parentheses can be used. If there is only
one argument, then no parentheses are required. Each argument in the list can include
 
 
Search WWH ::




Custom Search