Definition of a Functional Interface
What you'll learn: You'll discover what makes an interface "functional" in Java and why this matters for modern Java programming.
The Core Concept
A functional interface is an interface that contains exactly one abstract method. That's it. This single-method contract is what makes the interface "functional" — it represents one function or behavior that can be implemented.
While functional interfaces can have multiple default methods, static methods, or methods inherited from Object, they must have precisely one abstract method that needs implementation.
Why This Matters
By having exactly one abstract method, functional interfaces create a clear, unambiguous target for implementation. This single-method structure is what enables you to use lambda expressions and method references — concise ways to implement that one behavior without verbose anonymous class syntax.
Think of a functional interface as a contract for a single action. Just as a light switch has one job (turn on/off), a functional interface defines one operation. This simplicity makes it perfect for passing behavior as a parameter or storing behavior in a variable.
The @FunctionalInterface Annotation
Java provides the @FunctionalInterface annotation to explicitly mark an interface as functional. While optional, it's helpful because the compiler will verify your interface truly has exactly one abstract method and will produce an error if you accidentally add a second one.
@FunctionalInterface
interface Validator {
boolean validate(String input);
// Only ONE abstract method
}
Without functional interfaces, you couldn't write the clean lambda-based collectors and stream operations you've been using. Every Predicate, Function, Consumer, and custom collector relies on this single-method principle.
Key Takeaway: A functional interface has exactly one abstract method, creating a clear contract that enables lambda expressions, method references, and the functional programming style you've been using throughout streams and collectors.