Java lambda expressions are unnamed methods, which are used to implement the abstract method of functional interface. Lambda expressions are also known as closures. They are used to call methods as  objects.

The lambda expressions are added in Java 8 and provide below functionalities.

  1. It enables to treat functionality as the method argument, or code as data.
  2. The function that can be created without belonging to any class.
  3. The lambda expression can be passed around as if it was an object and executed on demand.

Java Lambda Expressions

Lambda expressions use the lambda operator (->) which divides the lambda expression into two parts. The part on the left side contains the parameters required by the lambda expression, and the part on the right side specifies the body of the lambda expression.

The parameters are enclosed in parenthesis, and the body is enclosed in curly braces.

Note: A functional interface is an  interface that contains only one abstract method. A functional interface is also known as SAM(Single Abstract Method) interface. @FunctionalInterface could be written to create a functional interface that will show an error if the properties of the functional interface got violated.

#java #lambda expressions #java 8

Java Lambda Expressions Example | Lambda Expression in Java
2.20 GEEK