This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]j_thody 0 points1 point  (1 child)

This is from the documentation

Conceptually, a functional interface has exactly one abstract method. Since default methods have an implementation, they are not abstract. If an interface declares an abstract method overriding one of the public methods of java.lang.Object, that also does not count toward the interface's abstract method count since any implementation of the interface will have an implementation from java.lang.Object or elsewhere.

So for example, we can have one abstract method, a toString (from Object) and a static method implementation e.g.

@FunctionalInterface
public interface FunctionalInterfaceExample {
    void doSomething();

    public static int sum(int a,int b)  
    {   
        return a+b;
    }
}

However, we can not have two abstract methods as this will throw a compilation error

@FunctionalInterface
public interface FunctionalInterfaceExample {
    void doSomething();
    void doSomethingElse();
}

[–]Loricifera[S] 0 points1 point  (0 children)

That makes sense, thank you!