Any interface with a SAM (Single Abstract Method) is a functional interface.
JDK is also using functional interface, i.e.

SAM(Single Abstract Method) is used by creating Anonymous Inner classes using these interfaces. For example:
0 1 2 3 4 5 6 7 8 9 10 11 |
public class AnonymousInnerClassTest { public static void main(String[] args) { new Thread(new Runnable() { @Override public void run() { System.out.println("created thread and calling run"); } }).start(); } } |
Above same concept is used by Functional interfaces.
Let’s look at example of functional interface:
0 1 2 3 4 5 |
@FunctionalInterface public interface SimpleFunctionalInterface { public void abstractMethod(); } |
The interface can also declare the abstract methods from the
0 1 2 3 4 5 6 7 8 9 |
@FunctionalInterface public interface SimpleFunctionalInterface { public void abstractMethod(); public String toString(); public boolean equals(Object o); } |
Once you add another abstract method, i.e.
You cannot have more than one method besides static, default and abstract methods that override methods in
Key Points
- Only one abstract method is allowed in any functional interface. More than one abstract method is not allowed by the compiler. If we remove
@FunctionalInterface then we are allowed to add another abstract method, but it will be the non functional interface. - A functional interface is valid even if the
@FunctionalInterface annotation would be omitted. It is only for informing the compiler to enforce single abstract method inside interface.