Object Class Methods Don't Count
What you'll learn: Why public methods inherited from Object don't add to the "single abstract method" count in functional interfaces.
When Java determines whether an interface is functional, it only counts abstract methods that the implementing class must define. Public methods from Object—like equals(), hashCode(), and toString()—are automatically inherited by every class, so they don't count toward the single abstract method (SAM) limit.
Why This Rule Exists
Every Java class already extends Object implicitly, which means these methods always have implementations available. When you implement a functional interface, you're not required to override equals() or toString()—they're already there. Since they don't represent additional obligations, they don't break the SAM rule.
Example: Still a Functional Interface
@FunctionalInterface
interface Comparator<T> {
int compare(T o1, T o2); // The ONE abstract method
boolean equals(Object obj); // From Object — doesn't count!
}
Even though Comparator declares equals(), it remains functional because equals() is inherited from Object. The only method you must implement is compare().
The Analogy
Think of it like a job posting: "We need someone who can code." Skills everyone already has (like "can breathe" or "can think") aren't listed as requirements. Similarly, methods every class already has don't count as additional requirements.
What Counts and What Doesn't
✅ Counts: Abstract methods with no implementation in Object
❌ Doesn't count: equals(), hashCode(), toString(), getClass(), notify(), etc.
❌ Doesn't count: Default methods, static methods (as you learned earlier)
Key Takeaway: Public methods from Object are "free" declarations in functional interfaces—they don't violate the single abstract method rule because every implementing class already has them.