What are lambda expressions in Java?

Java 8Object Oriented ProgrammingProgramming

The implementation of functional interfaces has simplified using lambda expressions in Java 8. The lambda expressions are functions as arguments in Java. The lambda expression introduces a new syntax element and operator in Java and refers to the lambda operator or the arrow operator (->).

Example

interface Print {
   void print(String message);
}
public class LambdaExpressionTest {
   public static void main(String args[]) {
      Print myPrint = x -> System.out.println(x);
      myPrint.print("Java Lambda Expression!");
   }
}

Output

Java Lambda Expression!
raja
Published on 02-Dec-2019 10:19:45
Advertisements