Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java
Expertise: Intermediate
Aug 25, 2017

Understanding Lambda Expresssions with a Simple Method Call

Lambda expressions have simplified the way we write code. For example, let's see how to use a method from an interface.

This works with Java 1.8 only. Expected output: Welcome to Lambda expressions

public class LambdaDemo
   public static void main(String args[])
      LambdaDemo lambdaDemo = new LambdaDemo();
      //Using the interface to print 
      WelcomeMessage welcomeMessage = welcomeString -
      System.out.println("Welcome " + welcomeString);
      welcomeMessage.printMessage("to Lambda expressions");
   //Interface definition
   interface WelcomeMessage {
      void printMessage(String welcomeString);
M S Sridhar
Thanks for your registration, follow us on our social networks to keep up-to-date