Top Description Methods
java.util.function

public Interface Function<T, R>

Known Direct Subinterfaces
java.util.function.UnaryOperator
Known Direct Implementers
jdk.internal.logger.BootstrapLogger.RedirectedLoggers, jdk.internal.module.ModuleLoaderMap.Mapper
Annotations
@FunctionalInterface
Type Parameters
<T>
the type of the input to the function
<R>
the type of the result of the function
Imports
java.util.Objects

Represents a function that accepts one argument and produces a result.

This is a functional interface whose functional method is apply(Object).

Since
1.8

Method Summary

Modifier and TypeMethod and Description
public default <
the type of output of the after function, and of the composed function
V
>
Function<T, V>

Returns:

a composed function that first applies this function and then applies the after function
andThen
(Function<? super R, ? extends V>
the function to apply after this function is applied
after
)

Returns a composed function that first applies this function to its input, and then applies the after function to the result.

public R

Returns:

the function result
apply
(T
the function argument
t
)

Applies this function to the given argument.

public default <
the type of input to the before function, and to the composed function
V
>
Function<V, R>

Returns:

a composed function that first applies the before function and then applies this function
compose
(Function<? super V, ? extends T>
the function to apply before this function is applied
before
)

Returns a composed function that first applies the before function to its input, and then applies this function to the result.

public static <
the type of the input and output objects to the function
T
>
Function<T, T>

Returns:

a function that always returns its input argument
identity
()

Returns a function that always returns its input argument.

Method Detail

andThenback to summary
public default <V> Function<T, V> andThen(Function<? super R, ? extends V> after)

Returns a composed function that first applies this function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.

Parameters
<V>
the type of output of the after function, and of the composed function
after:Function<? super R, ? extends V>

the function to apply after this function is applied

Returns:Function<T, V>

a composed function that first applies this function and then applies the after function

Exceptions
NullPointerException:
if after is null
See Also
compose(Function)
applyback to summary
public R apply(T t)

Applies this function to the given argument.

Parameters
t:T

the function argument

Returns:R

the function result

composeback to summary
public default <V> Function<V, R> compose(Function<? super V, ? extends T> before)

Returns a composed function that first applies the before function to its input, and then applies this function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.

Parameters
<V>
the type of input to the before function, and to the composed function
before:Function<? super V, ? extends T>

the function to apply before this function is applied

Returns:Function<V, R>

a composed function that first applies the before function and then applies this function

Exceptions
NullPointerException:
if before is null
See Also
andThen(Function)
identityback to summary
public static <T> Function<T, T> identity()

Returns a function that always returns its input argument.

Parameters
<T>
the type of the input and output objects to the function
Returns:Function<T, T>

a function that always returns its input argument