What is a functional interface?

A functional interface is a special type of interface that defines a function type or callback.

For the compiler to recognize an interface as functional, it must declare exactly one abstract method. In addition, it can contain any number of default methods with bodies. Redefinitions of Object class methods are also ignored.

There are no other restrictions on the method: it is not limited in the types of arguments or return values, and it can have any name and any list of thrown exceptions (both checked and unchecked).

Even if all these conditions are met, no other types besides interfaces can be considered functional interfaces.

Additionally, it's customary to mark a functional interface with the @FunctionalInterface annotation. This annotation is not required, but it provides extra validation: its presence on a non-functional type will trigger a compilation error.

Typical examples of functional interfaces are Callable, Supplier, and Comparable.
What is a functional interface?