Example of a Functional Interface

Also called a SAM (Single Abstract Method). An FI is an interface containing :

  • One and only one abstract method;
  • Zero or many static methods
  • Zero or many default methods

There are many built-in functional interfaces included in Java 8. The Predicate FI is one of them.

Here is an example of a functional interface :

@FunctionalInterface
interface MostBasicFi{
   boolean test();

   // a static method
   public static void foo1(){
    // add some logic...
   }

   // a default method
   public static void foo2(){
    // add some logic...
   }
   
}