No comments yet

What is a functional interface in Java 8?

[Social9_Share type="horizontal"]

Functional Interface in Java 8

In this blog lets discuss about the functional interface in Java 8

What is a functional interface?

A functional interface is an interface with only one abstract method. But it can have default and static methods. You can also annotate this interface with @FunctionalInterface, though not mandatory. This annotation helps to check in the compile time if this is a functional interface.If you try to annotate an interface having more than one abstract method with @FunctionalIterface, then it will give compiler error.

java.lang.Comparable, java.lang.Runnable are few examples of functional interface. Java 8 has introduced a lot of functional interfaces to work with Lambda expressions. Function, Predicate,Consumer, Supplier, BiPredicate, BiConsumer are few functional interfaces introduced in Java 8.


The functional interfaces can be implemented using anonymous inner classes or Lambda expressions.To learn how to use lambda expressions with functional interfaces click here .

Thats all
Happy Learning

Post a comment