Functional Interfaces Definition

Description

A functional interface is an interface that has one abstract method.

We cannot use the following types of methods to declare a functional interface:

  • Default methods
  • Static methods
  • Methods inherited from the Object class

A functional interface can redeclare the methods in the Object class. And that method is not counted as abstract method. Therefore we can declare another method used by lambda expression.

Consider the Comparator class in the java.util package, as shown:


package java.util;
//  w  ww.jav  a2s. c  om
@FunctionalInterface
public interface  Comparator<T> {
   // An  abstract method  declared in the functional interface 
   int compare(T  o1,   T  o2);

   // Re-declaration of the equals() method in the Object class 
   boolean equals(Object  obj);

   ...
}

The Comparator interface has two abstract methods: compare() and equals().

The equals() method is a redeclaration of the equals() method from the Object class.





















Home »
  Java Lambda »
    Java Lambda Tutorial »




Java Lambda Tutorial