Search code examples
javafunctional-interface

Java functional interface


I am new to Java8 and I read a couple of things about this topic on the Internet. For the moment I am trying to figure out what functional interfaces are. I've found some examples, but I do not understand why the interface Skip is a functional one, since it has 2 defined methods. I hope that someone can explain me a bit. The code is:

 @FunctionalInterface
 public interface Sprint 
 {
     public void sprint(Animal animal);
 }


 @FunctionalInterface
 public interface Skip extends Sprint 
 {

      public default int getHopCount() 
      {
         return 10;
      }

      public static void skip(int speed) {}
 }

Solution

  • Your Skip interface has only one abstract method (default and static methods don't count) - the sprint method inherited from the Sprint interface. Therefore it is a functional interface.