functional interface and function descriptor



Functional Interface:
  • An interface with exactly one abstract method is called functional interface.
  • Lamda expression can work for the functional interfaces only.
  • Java 8 has introduced lot more functional interfaces.
  • Even streams filter(), map() and other methods also takes lamda expression as an argument.
Example of functional interface:
@FunctionalInterface

public interface Predicate<T>{
    boolean test (T t); // function descriptor
}

 
@FunctinalInterface
public interface Consumer<T> {
    void accept(T t) ;
}

Function Descriptor:
An abstract method in the functional interface which describes the complete prototype of method is called function descriptor. In above function interface  boolean test (T t); is a function descriptor.

@FunctionalInterface:
In java API you can see that all the functional interfaces are annotated with the @FunctionalInterface annotation.
you should also use this annotation on your custom user defined functional interfaces.
An interface annotated with @FunctionalInterface and if it not a functional interface then
compiler gives appropriate error. Same as @Override annotation.