© Ralph Lecessi 2019
Ralph LecessiFunctional Interfaces in Javahttps://doi.org/10.1007/978-1-4842-4278-0_4

4. Functions

Ralph Lecessi1 
(1)
Kendall Park, NJ, USA
 

Section 4.1: The Function Interface

Function is a functional interface with two type parameters T and R. Its functional method, called apply, takes an argument of type T and returns an object of type R. Functions are ideal for converting an object of type T to one of type R.
@FunctionalInterface
public interface Function<T, R>
{
    R apply(T t);
    ...
}
A Function of String, Integer type is declared as follows:
    Function<String, Integer> f;
Function f’s apply method will accept a String argument and return an Integer. The following statement represents this function using a lambda expression: ...

Get Functional Interfaces in Java: Fundamentals and Examples now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.