Functional Interface in Java 8 or Above
Functional Interface
Functional Interface is new concepts in Java after version 1.8, It is the core striking features in version 1.8, because of a functional interface, other features of java 1.8 exists like Lambda expression, method references, Java.util.function packages and Java Stream API. All these features are 100% dependent on functional interface. This functional interface concept brings again Java to stand strongly in front of the functional programming supported languages like Python, Ruby, etc.
It is not a new kind of interface; it is an old one but with some restrictions. An Interface, which allows only one abstract method declaration with @FunctionalInterface annotation is called Functional Interface. In Function Interfaces, more than one default, or static method is allowing and you can also write java.lang.Object class methods, but more than one abstract method is not allowed.
Let’s understand it by example:
@FunctionalInterface
interface Message {
public abstract void msg ();
}
public class Main implements Message {
public void msg ()
{
System.out.println(“This is Functional Interface Method”);
}
public static void main (String args )
{
Message m1 = new Main ();
m1.msg();
}
}
Advantages of Functions Interfaces:
1. To develop function programming in Java
2. To develop lambda expression in Java
3. To develop method references in Java
For more information your can watch this video: