JAVA 8 Features

Akhila unique
Apr 5, 2021

Let’s discuss the most important feature of java 8 i.e Lambda Expression

What is Lambda Expression?

ans) it is an Anonymous function

- In Brief, it is a method with

-No Name, No return type, No modifier

-The Expression is represented as ( ->)

How to Write a Lambda Expression?

public int getSum(int x, int y)
{
return x+y;
}

converting into Lambda Exp

(int x, int y)->{return x+y;}

Rules to convert Lambda Exp into optimum expression…

Rule1: if there is Single line in the body then remove {}

The above expression can be converted as

(int x, int y)->return x+y;

Rule2: Ignore the return statement

(int x, int y)->x+y;

Rule3: Ignore the parameter type since it can be guessed by compiler

(x, y)->x+y;

This is the final optimum form of the lambda expression to get sum of 2 numbers

(x, y)->x+y;

--

--