Java Reference
In-Depth Information
There is an entire book dedicated to lambda expressions and related tools, Richard Warbur-
ton's Java 8 Lambdas (O'Reilly).
Using Lambdas/Closures Instead of Inner Classes
Problem
You want to avoid all the typing that even the anonymous style of inner class requires.
Solution
Use Java's lambda expressions.
Discussion
The symbol lambda (λ) is the 11th letter of the Greek alphabet, and thus as old as Western
society. The Lambda Calculus is about as old as our notions of computing. In this context,
Lambda expressions are small units of calculation that can be referred to . They are “func-
tions as data.” In that sense, they are a lot like anonymous inner classes, though it's probably
better to think of them as anonymous methods . They are essentially used to replace inner
classes for a functional interface —that is, an interface with one abstract method (“function”)
in it. A very common example is the AWT ActionListener interface, widely used in GUI
code, whose only method is:
Search WWH ::




Custom Search