0 votes
in JAVA by (30.8k points)
What is a functional interface in Java 8?

1 Answer

0 votes
by (30.8k points)

As the name suggests, a functional interface is an interface that represents a function. Technically, an interface with just one abstract method is called a functional interface.

You can also use @FunctionalInterface to annotated a functional interface. In that case, the compiler will verify if the interface actually contains just one abstract method or not. It's like the @Override annotation, which prevents you from accidental errors.

Another useful thing to know is that If a method accepts a functional interface, then you can pass a lambda expression to it.

Some examples of the functional interface are Runnable, Callable, Comparator, and Comparable from old API and Supplier, Consumer, and Predicate, etc. from new function API. You can learn more about those interfaces in Java What's New in Java 8 on Pluralsight.

Related questions

0 votes