Interview Question

What is a functional interface?

A functional interface supplies the single abstract function type for a lambda.

💡 Concept ✅ Quick Revision ☕ Java

Answer

A functional interface has one abstract method for lambda-expression and method-reference targeting. • Object public methods do not count as additional abstract methods for this rule. • Default and static methods are allowed. • @FunctionalInterface asks the compiler to verify the contract.

Example

Code
@FunctionalInterface
interface Operation {
    int apply(int a, int b);
}
Operation add = (a, b) -> a + b;
System.out.println(add.apply(2, 3));
Output
5

Quick Revision

A functional interface supplies the single abstract function type for a lambda.