Comp 110 Functional Interfaces

Functional Interfaces

A function's type includes the number, order, and type of its parameters as well as its return type. We can name these function types using functional interfaces. Functional interfaces are nice since they let us use functions that have function parameters so we can pass in the logic we want to implement. Functions that take other functions as parameters are higher-order functions.

Here's the general format for functional interfaces:

interface Name {  
    (parameter: type,...): returnType;
}

We can also use what we know about generics to make generic functional interfaces. To make a functional interface generic, we need to have our type placeholder in brackets, <T>. This goes right after the name of the interface to signify that it is generic, then we can specify where we want to use this type just as we do in generic functions:

interface Name<T> {  
    (parameter: T,...): returnType;
}