Annotation Interface FunctionalInterface


@Documented@Retention(RUNTIME)@Target(TYPE)public @interfaceFunctionalInterface
An informative annotation type used to indicate that an interfacetype declaration is intended to be afunctional interface asdefined by the Java Language Specification.Conceptually, a functional interface has exactly one abstractmethod. Sincedefault methods have an implementation, they are not abstract. Ifan interface declares an abstract method overriding one of thepublic methods ofjava.lang.Object, that also doesnot count toward the interface's abstract method countsince any implementation of the interface will have animplementation fromjava.lang.Object or elsewhere.

Note that instances of functional interfaces can be created withlambda expressions, method references, or constructor references.

If a type is annotated with this annotation type, compilers arerequired to generate an error message unless:

  • The type is an interface type and not an annotation type, enum, or class.
  • The annotated type satisfies the requirements of a functional interface.

However, the compiler will treat any interface meeting thedefinition of a functional interface as a functional interfaceregardless of whether or not aFunctionalInterfaceannotation is present on the interface declaration.

SeeJava Language Specification:
4.3.2 The Class Object
9.8 Functional Interfaces
9.4.3 Interface Method Body
9.6.4.9 @FunctionalInterface
Since:
1.8