Lambda Expressions

Lambda Expressions


-> Lambda Expression is an anonymous function used for passing function as argument or creating inline functions without formal method declarations.

Syntax: (parameter list) -> expression body

for using lambda we need a functional interface .

package com.mn.inteface;

@FunctionalInterface
public interface FInterface {
	// should contain only one abstract method
	public String displayFunction();

}        

Implementing and calling Functional Interface using lambda expression

package com.mn.main;

import com.mn.inteface.FInterface;

public class ShowLambda {

	public static void main(String[] args) {
	// We are implementing functional interface using lambda exp.
	FInterface l = () -> "It is Funtional Interface";

	// calling and printing the Function
	System.out.println(l.displayFunction());
	}

}

output: It is Funtional Interface        

To view or add a comment, sign in

More articles by Manohar Grandhi

Explore content categories