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. It can also declare the methods of the object class.
Functional Interface is also known as Single Abstract Method Interfaces or SAM Interfaces. A functional interface can extend another interface only when it does not have any abstract method.
Java 8 provides predefined functional interfaces to deal with functional programming by using lambda and method references.
For example:
interface Printable {
void print(String msg);
}
public class JLEExampleSingleParameter {
public static void main(String[] args) {
// with lambda expression
Printable withLambda = (msg) -> System.out.println(msg);
withLambda.print(" Print message to console....");
}
}
Output :
Print message to console....