Function – Functional interface in java 8

/, Java 8/Function – Functional interface in java 8

What is Function interface in java 8?

Function interface is exactly same as predicates except that functions can return any type of result but function should(can) return only one value and that value can be any type. This is a functional interface whose functional method is apply(Object).

Function interface present in java.util.function package. As this is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

Function interface methods :

Modifier and Type Method and Description
default 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.
R apply(T t)

Applies this function to the given argument.
default 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.
static Function<T,T> identity()

Returns a function that always returns its input argument.

apply()

compose()

andThen()

identity()

identity() – Returns a function that always returns its input argument.

 

Leave A Comment