Why do I need a functional Interface to work with lambdas?

When you write :

TestInterface i = () -> System.out.println("Hans");

You give an implementation to the void hans() method of the TestInterface.

If you could assign a lambda expression to an interface having more than one abstract method (i.e. a non functional interface), the lambda expression could only implement one of the methods, leaving the other methods unimplemented.

You can’t solve it by assigning two lambda expressions having different signatures to the same variable (Just like you can’t assign references of two objects to a single variable and expect that variable to refer to both objects at once).

Leave a Comment