Last Updated: 28 May, 2022
Functional Interface was introduced in Java 8.
An Interface that contains only one abstract method is known as a Functional Interface in Java. It is also known as Single Abstract Method Interfaces or SAM Interfaces.
A functional interface can have any number of default methods or static methods but an abstract method must be only one. A functional interface can have methods of the Object class.
Before Java 8, We had to use anonymous inner class objects to implement functional interfaces.
Java Functional Interface
Output
Web URL: https://javabytechie.com
Any Interface that contains only one abstract method is treated as a Functional Interface in Java but if we have to ensure that Interface must be a functional interface and contains only one abstract method we should declare that interface with @FunctionalInterface
Annotation.
Java Functional Interface with @FunctionalInterface Annotation
Output
Web URL: https://javabytechie.com
Java allows to declare any number of default methods and static methods inside functional interface. Let's understand it with the help of given example.
Example 3 : Functional Interface with default methods and static methods
Output
Sandeep
Bangalore
Karnataka
560021
INDIA
That's all guys, hope this Java article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com