Java 8 - Project Lambda
What is project lambda:
Project lambda is the project to enable lambda expressions in java language syntax. Lambda expressions are major syntax in functional programming languages like lisp. Groovy would be the closest relative of java that has support for lambda expressions, also known as closures.
It is a block of code that can be assigned to a variable or passed as an argument to a method or passed as an argument to another lambda expression just like any other data
The main motivation behind supporting this in java is to remove a lot of boiler plate code in using certain API that require some code from the API user, but end up using inner classes just because of java's syntax requirements.
The syntax is indeed much simpler than that for creating anonymous classes. The syntax mainly is of this form:
argumentList -> body
The argumentList is just like java method argument list - comma separated and enclosed in parentheses, with one exception - if there is only one argument, the parentheses are optional. Also it is optional to mention the types of the arguments. In case the types are not specified, they are inferred. The body can be of two types - expression body and code block body. An expression body is just a valid java expression that returns a value. A code block body contains a code block just like a method body. The code block body has the same syntax as the method body including the mandatory pair of braces.
Project Lambda: To Multicore and Beyond
Where are we?
· Multicore hardware is now the default
· Moore’s law delivering more cores, not faster cores
· We must learn to write software that parallelizes gracefully
· All components of the Java SE platform – language, libraries, and VM – are co-evolving to meet the challenge
Goal: To achieve parallel computation when we invoke the methods through Lambda Expression
PFA.. for detail implementation