DEV Community

Discussion on: Java lambda expressions recap

Collapse
 
orenovadia profile image
orenovadia

Thanks for the post Erik.

What does the @FunctionalInterface do?

I thought that: for any one-method interface, Java knows how to cast a lambda expression to an instance of the interface, even without this annotation.

Collapse
 
erikpischel profile image
Erik Pischel

orenovadia, your right: the annotation is not needed.

The @FunctionalInterface annotation enables the compiler to report an error if the interface is not a functional interface, i.e. it has exactly one abstract method. Beside that, it communicates the intend that the interface is a functional interface to the reader.

Collapse
 
orenovadia profile image
orenovadia

Got it, thank you!