Lambda Expressions

Lambda expression is a Java 8 feature, which helps the developer to simplify syntax of anonymous interface implementation whenever required.

Interface is defined anonymously in earlier Java Implementation in the below old syntax., which is very much reduced in Java 8 lambda implementation, comparison of the below example provide a clear view of Lambda expression.

1. Native Java Implementation:

In this example, Calculator is a class, where Operation is inner object implementation, and the actual operation process is not defined in the application, operation implementation is defined when the Calculator Object is created.

Hence Interface is implemented anonymously by the Composite class ‘Calculator’.

2. Lambda Java Implementation:

In this example, Using Lambda expression, we can defining the operation object for additionCalculator and subtractCalculator in a very much quicker way. ->

Leave a Reply

Your email address will not be published. Required fields are marked *