Java - Functional Interface

About

Functional Programming - Functional Interface in Java.

A functional interface is is a interface that contains only one abstract method.

The interface is so simple that java defines several standard (built-in) functional interfaces

Usage

Functional interfaces represent abstract concepts like:

Structure

A functional interface is is a interface that contains only one abstract method.

The single abstract method is called the functional method.

It may contain one or more:

Annotation

The FunctionalInterface annotation is an aid to capture design intent not a requirement. Compilers may generate an error.

Method

The single abstract method in a function interface is called the functional method.

Creation

Implementation of functional interfaces can be created with:

Standard

The predefined/standard/built-in function interface can find in the package java.util.function package

They are generic interface.

All standard interface follows the following naming convention.

interface Predicate<T> {
    boolean test(T t);
}
interface Consumer<T> {
    void accept(T t);
}
  • Function (unary function from T to R), - abstract method that returns a value (Example: retrieve information or validation)
interface Function<T> {
   R apply(T t);
}
interface UnaryOperator<T> {
   T apply(T t);
}

Powered by ComboStrap