Functional Interfaces in java

Tue, Dec 3, 2019

Read in 1 minutes

What is functional interface?

Some of the functional Interfaces :

Lambda expression is used to represent the functional interface. If you add more than one abstract method for the functional interface, you will get an error in representing the functional interface. So, the thumb rule to be followed is,

Functional interface should have only one abstract method and that rule can be verifed by “@FunctionalInterface ” annotation.

@FunctionalInterface
public interface FunctionalInterfaceDemo {
	public String sayHello(String s);
	default String covertUpperCase(String s) {
		String result =s.toUpperCase();
		return result;
	}
}

If you try to add more than one abstract method, you will get the below error.

about-single-origin