Stay organized with collections
Save and categorize content based on your preferences.
Function
public
interface
Function
java.util.function.Function<T, R>
|
Known indirect subclasses
UnaryOperator<T> |
Represents an operation on a single operand that produces a result of the
same type as its operand.
|
|
Represents a function that accepts one argument and produces a result.
This is a functional interface
whose functional method is apply(java.lang.Object)
.
Summary
Public methods |
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.
|
abstract
R
|
apply(T t)
Applies this function to the given argument.
|
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.
|
static
<T>
Function<T, T>
|
identity()
Returns a function that always returns its input argument.
|
Public methods
andThen
public 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 |
after |
Function : 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 |
apply
public abstract R apply (T t)
Applies this function to the given argument.
Parameters |
t |
T : the function argument |
Returns |
R |
the function result |
compose
public 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 |
before |
Function : 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 |
identity
public static Function<T, T> identity ()
Returns a function that always returns its input argument.
Returns |
Function<T, T> |
a function that always returns its input argument |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# Function\n\nAdded in [API level 24](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Methods](#pubmethods) \n\nFunction\n========\n\n\n`\npublic\n\n\ninterface\nFunction\n`\n\n\n`\n\n\n`\n\n|-------------------------------------|\n| java.util.function.Function\\\u003cT, R\\\u003e |\n\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known indirect subclasses [UnaryOperator](/reference/java/util/function/UnaryOperator)\\\u003cT\\\u003e |-------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------| | [UnaryOperator](/reference/java/util/function/UnaryOperator)\\\u003cT\\\u003e | Represents an operation on a single operand that produces a result of the same type as its operand. | |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nRepresents a function that accepts one argument and produces a result.\n\nThis is a [functional interface](/reference/java/util/function/package-summary)\nwhose functional method is [apply(java.lang.Object)](/reference/java/util/function/Function#apply(T)).\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` default \u003cV\u003e `[Function](/reference/java/util/function/Function)`\u003cT, V\u003e` | ` `[andThen](/reference/java/util/function/Function#andThen(java.util.function.Function\u003c?%20super%20R,?%20extends%20V\u003e))`(`[Function](/reference/java/util/function/Function)`\u003c? super R, ? extends V\u003e after) ` Returns a composed function that first applies this function to its input, and then applies the `after` function to the result. |\n| ` abstract R` | ` `[apply](/reference/java/util/function/Function#apply(T))`(T t) ` Applies this function to the given argument. |\n| ` default \u003cV\u003e `[Function](/reference/java/util/function/Function)`\u003cV, R\u003e` | ` `[compose](/reference/java/util/function/Function#compose(java.util.function.Function\u003c?%20super%20V,?%20extends%20T\u003e))`(`[Function](/reference/java/util/function/Function)`\u003c? super V, ? extends T\u003e before) ` Returns a composed function that first applies the `before` function to its input, and then applies this function to the result. |\n| ` static \u003cT\u003e `[Function](/reference/java/util/function/Function)`\u003cT, T\u003e` | ` `[identity](/reference/java/util/function/Function#identity())`() ` Returns a function that always returns its input argument. |\n\nPublic methods\n--------------\n\n### andThen\n\nAdded in [API level 24](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic Function\u003cT, V\u003e andThen (Function\u003c? super R, ? extends V\u003e after)\n```\n\nReturns a composed function that first applies this function to\nits input, and then applies the `after` function to the result.\nIf evaluation of either function throws an exception, it is relayed to\nthe caller of the composed function.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|---------|-------------------------------------------------------------------------|\n| `after` | `Function`: the function to apply after this function is applied \u003cbr /\u003e |\n\n| Returns ||\n|------------------------------------------------------------|---------------------------------------------------------------------------------------------------|\n| [Function](/reference/java/util/function/Function)`\u003cT, V\u003e` | a composed function that first applies this function and then applies the `after` function \u003cbr /\u003e |\n\n| Throws ||\n|-------------------------------------------------------------------|------------------|\n| [NullPointerException](/reference/java/lang/NullPointerException) | if after is null |\n\n**See also:**\n\n- [compose(Function)](/reference/java/util/function/Function#compose(java.util.function.Function\u003c?%20super%20V,?%20extends%20T\u003e)) \n\n### apply\n\nAdded in [API level 24](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract R apply (T t)\n```\n\nApplies this function to the given argument.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----|-----------------------------------|\n| `t` | `T`: the function argument \u003cbr /\u003e |\n\n| Returns ||\n|-----|----------------------------|\n| `R` | the function result \u003cbr /\u003e |\n\n### compose\n\nAdded in [API level 24](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic Function\u003cV, R\u003e compose (Function\u003c? super V, ? extends T\u003e before)\n```\n\nReturns a composed function that first applies the `before`\nfunction to its input, and then applies this function to the result.\nIf evaluation of either function throws an exception, it is relayed to\nthe caller of the composed function.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|--------------------------------------------------------------------------|\n| `before` | `Function`: the function to apply before this function is applied \u003cbr /\u003e |\n\n| Returns ||\n|------------------------------------------------------------|----------------------------------------------------------------------------------------------------|\n| [Function](/reference/java/util/function/Function)`\u003cV, R\u003e` | a composed function that first applies the `before` function and then applies this function \u003cbr /\u003e |\n\n| Throws ||\n|-------------------------------------------------------------------|-------------------|\n| [NullPointerException](/reference/java/lang/NullPointerException) | if before is null |\n\n**See also:**\n\n- [andThen(Function)](/reference/java/util/function/Function#andThen(java.util.function.Function\u003c?%20super%20R,?%20extends%20V\u003e)) \n\n### identity\n\nAdded in [API level 24](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic static Function\u003cT, T\u003e identity ()\n```\n\nReturns a function that always returns its input argument.\n\n\u003cbr /\u003e\n\n| Returns ||\n|------------------------------------------------------------|----------------------------------------------------------|\n| [Function](/reference/java/util/function/Function)`\u003cT, T\u003e` | a function that always returns its input argument \u003cbr /\u003e |"]]