Package java.util.function
See: Description
-
Interface Summary Interface Description BiConsumer<T,U> Represents an operation that accepts two input arguments and returns no result.BiFunction<T,U,R> Represents a function that accepts two arguments and produces a result.BinaryOperator<T> Represents an operation upon two operands of the same type, producing a result of the same type as the operands.BiPredicate<T,U> Represents a predicate (boolean-valued function) of two arguments.BooleanSupplier Represents a supplier ofboolean
-valued results.Consumer<T> Represents an operation that accepts a single input argument and returns no result.DoubleBinaryOperator Represents an operation upon twodouble
-valued operands and producing adouble
-valued result.DoubleConsumer Represents an operation that accepts a singledouble
-valued argument and returns no result.DoubleFunction<R> Represents a function that accepts a double-valued argument and produces a result.DoublePredicate Represents a predicate (boolean-valued function) of onedouble
-valued argument.DoubleSupplier Represents a supplier ofdouble
-valued results.DoubleToIntFunction Represents a function that accepts a double-valued argument and produces an int-valued result.DoubleToLongFunction Represents a function that accepts a double-valued argument and produces a long-valued result.DoubleUnaryOperator Represents an operation on a singledouble
-valued operand that produces adouble
-valued result.Function<T,R> Represents a function that accepts one argument and produces a result.IntBinaryOperator Represents an operation upon twoint
-valued operands and producing anint
-valued result.IntConsumer Represents an operation that accepts a singleint
-valued argument and returns no result.IntFunction<R> Represents a function that accepts an int-valued argument and produces a result.IntPredicate Represents a predicate (boolean-valued function) of oneint
-valued argument.IntSupplier Represents a supplier ofint
-valued results.IntToDoubleFunction Represents a function that accepts an int-valued argument and produces a double-valued result.IntToLongFunction Represents a function that accepts an int-valued argument and produces a long-valued result.IntUnaryOperator Represents an operation on a singleint
-valued operand that produces anint
-valued result.LongBinaryOperator Represents an operation upon twolong
-valued operands and producing along
-valued result.LongConsumer Represents an operation that accepts a singlelong
-valued argument and returns no result.LongFunction<R> Represents a function that accepts a long-valued argument and produces a result.LongPredicate Represents a predicate (boolean-valued function) of onelong
-valued argument.LongSupplier Represents a supplier oflong
-valued results.LongToDoubleFunction Represents a function that accepts a long-valued argument and produces a double-valued result.LongToIntFunction Represents a function that accepts a long-valued argument and produces an int-valued result.LongUnaryOperator Represents an operation on a singlelong
-valued operand that produces along
-valued result.ObjDoubleConsumer<T> Represents an operation that accepts an object-valued and adouble
-valued argument, and returns no result.ObjIntConsumer<T> Represents an operation that accepts an object-valued and aint
-valued argument, and returns no result.ObjLongConsumer<T> Represents an operation that accepts an object-valued and along
-valued argument, and returns no result.Predicate<T> Represents a predicate (boolean-valued function) of one argument.Supplier<T> Represents a supplier of results.ToDoubleBiFunction<T,U> Represents a function that accepts two arguments and produces a double-valued result.ToDoubleFunction<T> Represents a function that produces a double-valued result.ToIntBiFunction<T,U> Represents a function that accepts two arguments and produces an int-valued result.ToIntFunction<T> Represents a function that produces an int-valued result.ToLongBiFunction<T,U> Represents a function that accepts two arguments and produces a long-valued result.ToLongFunction<T> Represents a function that produces a long-valued result.UnaryOperator<T> Represents an operation on a single operand that produces a result of the same type as its operand.
Package java.util.function Description
// Assignment context
Predicate<String> p = String::isEmpty;
// Method invocation context
stream.filter(e -> e.getSize() > 10)...
// Cast context
stream.map((ToIntFunction) e -> e.getSize())...
The interfaces in this package are general purpose functional interfaces used by the JDK, and are available to be used by user code as well. While they do not identify a complete set of function shapes to which lambda expressions might be adapted, they provide enough to cover common requirements. Other functional interfaces provided for specific purposes, such as FileFilter
, are defined in the packages where they are used.
The interfaces in this package are annotated with FunctionalInterface
. This annotation is not a requirement for the compiler to recognize an interface as a functional interface, but merely an aid to capture design intent and enlist the help of the compiler in identifying accidental violations of design intent.
Functional interfaces often represent abstract concepts like functions, actions, or predicates. In documenting functional interfaces, or referring to variables typed as functional interfaces, it is common to refer directly to those abstract concepts, for example using "this function" instead of "the function represented by this object". When an API method is said to accept or return a functional interface in this manner, such as "applies the provided function to...", this is understood to mean a non-null reference to an object implementing the appropriate functional interface, unless potential nullity is explicitly specified.
The functional interfaces in this package follow an extensible naming convention, as follows:
- There are several basic function shapes, including
Function
(unary function fromT
toR
),Consumer
(unary function fromT
tovoid
),Predicate
(unary function fromT
toboolean
), andSupplier
(nilary function toR
). - Function shapes have a natural arity based on how they are most commonly used. The basic shapes can be modified by an arity prefix to indicate a different arity, such as
BiFunction
(binary function fromT
andU
toR
). - There are additional derived function shapes which extend the basic function shapes, including
UnaryOperator
(extendsFunction
) andBinaryOperator
(extendsBiFunction
). - Type parameters of functional interfaces can be specialized to primitives with additional type prefixes. To specialize the return type for a type that has both generic return type and generic arguments, we prefix
ToXxx
, as inToIntFunction
. Otherwise, type arguments are specialized left-to-right, as inDoubleConsumer
orObjIntConsumer
. (The type prefixObj
is used to indicate that we don't want to specialize this parameter, but want to move on to the next parameter, as inObjIntConsumer
.) These schemes can be combined, as inIntToDoubleFunction
. - If there are specialization prefixes for all arguments, the arity prefix may be left out (as in
ObjIntConsumer
).
- Since:
- 1.8
- See Also:
-
FunctionalInterface
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2022, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.