Lambda Expression in Java 8

A hot topic in Java 8 is support for lambda expressions. They are part of Java Specification Request (JSR 335). I wrote about closures in Java two years back. Lambda expression are informally called as closures. We are closer to the release of Java 8 and lets see how it is implemented.
Lambda expressions are similar to methods, it has arguments, a body and return type. They can also be called as anonymous methods. A method without name.

One of the main features of lambda expressions is it enables passing a method as argument to another method. I see that because of this feature it is going to unravel umpteen programming possibilities.

Functional Interfaces

An interface with no method is a marker interface. An interface with only one abstract method is a functional interface. ActionListener class is an example of functional interface. We use anonymous class to implement ActionListener and in this kind of scenario, instead of using anonymous inner classes to implement, lambda expressions can be used. It will be simple and better compared to anonymous inner classes.
Need JDK8 to experiment with lambda expressions. Presently JDK 8 is available as snapshot release JDK 8 Build b 84.

0 comments:

Post a Comment