Sobes.tech
Junior — Middle

What is the maximum number of methods allowed in a functional interface?

sobes.tech AI

Answer from AI

In Android (more precisely in Java), a functional interface must contain exactly one abstract method. This restriction is related to the fact that functional interfaces are intended to be used with lambda expressions and method references.

Therefore, the maximum number of abstract methods in a functional interface is one. At the same time, the interface can contain any number of default or static methods.

Example of a functional interface:

@FunctionalInterface
public interface MyFunction {
    void apply(); // the only abstract method

    default void log() {
        System.out.println("Logging");
    }
}
What is the maximum number of methods allowed in a… - sobes.tech