Functional Interfaces

 

An Interface that contains exactly one abstract method is known as a functional interface. It can have any number of default, static methods but can contain only one abstract method. Functional Interface is also known as Single Abstract Method Interfaces or SAM Interfaces. It is a new feature in Java, which helps to achieve functional programming approach.

 

@FunctionalInterface
public interface AdditionalCalculator {

	int add(int num1, int num2);
}
public class FunctionalInterfaceDemo {

	public static void main(String[] args) {
		AdditionalCalculator add = (int num1, int num2) -> num1+num2;
		
		System.out.println(add.add(2, 4));
	}
}

Result

6

 

 

 

 

 

 

 

 

 




Subscribe To Our Newsletter
You will receive our latest post and tutorial.
Thank you for subscribing!

required
required


Leave a Reply

Your email address will not be published.