About FunctionalInterface Annotation

Kaan Yamanyar kaan at yamanyar.com
Thu Sep 19 00:40:47 PDT 2013


According to javadoc of FunctionalInterface the compiler will treat any
interface meeting the definition of a functional interface as a functional
interface regardless of whether or not a FunctionalInterface annotation is
present on the interface declaration.

Let's assume there are two libraries (jar) I am using as a developer : A,B.

Library "A" has an interface without the annotation and library "B" makes
use of this interface using it as a functional interface.

Meanwhile I upgraded version of library "A" due to some new features I need
and let's assume that developers of "A" added one more method to interface
which "B" was using as functional interface.

Now I am going to have runtime exceptions from library "B" due to fact that
the functional interface it assumes is not a functional interface any more.

Should we accept that all developers writing an interface knows the usage
of "functional interface" and accept this problem?

Wouldn't it be discouraging for developers to use method referencing?

Or am I totally misunderstood the issue :)?

Kaan Yamanyar

*Kaan Yamanyar*

kaan at yamanyar.com

More information about the lambda-dev mailing list