Return to site

JAVA ANNOTATIONS: @FunctionalInterface

=>indicates that the type declaration is intended to be a functional interface

· java

Define

An informative annotation type used to indicate that an interface type declaration is intended to be a functional interface as defined by the Java Language Specification. Conceptually, a functional interface has exactly one abstract method.

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

If a type is annotated with this annotation type, compilers are required 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.

Snippet

@FunctionalInterface  
interface sayable{  
  void say(String msg);  
}  
public class FunctionalInterfaceExample implements sayable{  
  public void say(String msg){  
    System.out.println(msg);  
  }  
  public static void main(String[] args) {  
    FunctionalInterfaceExample fie = new FunctionalInterfaceExample();  
    fie.say("Hello there");  
  }  
}