// 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 java.
, are defined in the packages where they
are used.
The interfaces in this package are annotated with
java.
. 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:
java.util.function.Function
(unary function from T
to R
),
java.util.function.Consumer
(unary function from T
to void
),
java.util.function.Predicate
(unary function from T
to boolean
),
and java.util.function.Supplier
(nullary function to R
).
java.util.function.BiFunction
(binary function from T
and
U
to R
).
java.util.function.UnaryOperator
(extends Function
) and java.util.function.BinaryOperator
(extends BiFunction
).
ToXxx
, as in java.util.function.ToIntFunction
.
Otherwise, type arguments are specialized left-to-right, as in
java.util.function.DoubleConsumer
or java.util.function.ObjIntConsumer
.
(The type prefix Obj
is used to indicate that we don't want to
specialize this parameter, but want to move on to the next parameter,
as in java.util.function.ObjIntConsumer
.)
These schemes can be combined, as in IntToDoubleFunction
.
java.util.function.ObjIntConsumer
).
java.lang.FunctionalInterface
Modifier and Type | Interface and Description |
---|---|
public interface | BiConsumer<
the type of the first argument to the operation T, the type of the second argument to the operation U>Represents an operation that accepts two input arguments and returns no result. |
public interface | BiFunction<
the type of the first argument to the function T, the type of the second argument to the function U, the type of the result of the function R>Represents a function that accepts two arguments and produces a result. |
public interface | BinaryOperator<
the type of the operands and result of the operator T>Represents an operation upon two operands of the same type, producing a result of the same type as the operands. |
public interface | BiPredicate<
the type of the first argument to the predicate T, the type of the second argument the predicate U>Represents a predicate (boolean-valued function) of two arguments. |
public interface | BooleanSupplier
Represents a supplier of |
public interface | Consumer<
the type of the input to the operation T>Represents an operation that accepts a single input argument and returns no result. |
public interface | DoubleBinaryOperator
Represents an operation upon two |
public interface | DoubleConsumer
Represents an operation that accepts a single |
public interface | DoubleFunction<
the type of the result of the function R>Represents a function that accepts a double-valued argument and produces a result. |
public interface | DoublePredicate
Represents a predicate (boolean-valued function) of one |
public interface | DoubleSupplier
Represents a supplier of |
public interface | DoubleToIntFunction
Represents a function that accepts a double-valued argument and produces an int-valued result. |
public interface | DoubleToLongFunction
Represents a function that accepts a double-valued argument and produces a long-valued result. |
public interface | DoubleUnaryOperator
Represents an operation on a single |
public interface | Function<
the type of the input to the function T, the type of the result of the function R>Represents a function that accepts one argument and produces a result. |
public interface | IntBinaryOperator
Represents an operation upon two |
public interface | IntConsumer
Represents an operation that accepts a single |
public interface | IntFunction<
the type of the result of the function R>Represents a function that accepts an int-valued argument and produces a result. |
public interface | IntPredicate
Represents a predicate (boolean-valued function) of one |
public interface | IntSupplier
Represents a supplier of |
public interface | IntToDoubleFunction
Represents a function that accepts an int-valued argument and produces a double-valued result. |
public interface | IntToLongFunction
Represents a function that accepts an int-valued argument and produces a long-valued result. |
public interface | IntUnaryOperator
Represents an operation on a single |
public interface | LongBinaryOperator
Represents an operation upon two |
public interface | LongConsumer
Represents an operation that accepts a single |
public interface | LongFunction<
the type of the result of the function R>Represents a function that accepts a long-valued argument and produces a result. |
public interface | LongPredicate
Represents a predicate (boolean-valued function) of one |
public interface | LongSupplier
Represents a supplier of |
public interface | LongToDoubleFunction
Represents a function that accepts a long-valued argument and produces a double-valued result. |
public interface | LongToIntFunction
Represents a function that accepts a long-valued argument and produces an int-valued result. |
public interface | LongUnaryOperator
Represents an operation on a single |
public interface | ObjDoubleConsumer<
the type of the object argument to the operation T>Represents an operation that accepts an object-valued and a
|
public interface | ObjIntConsumer<
the type of the object argument to the operation T>Represents an operation that accepts an object-valued and a
|
public interface | ObjLongConsumer<
the type of the object argument to the operation T>Represents an operation that accepts an object-valued and a
|
public interface | Predicate<
the type of the input to the predicate T>Represents a predicate (boolean-valued function) of one argument. |
public interface | |
public interface | ToDoubleBiFunction<
the type of the first argument to the function T, the type of the second argument to the function U>Represents a function that accepts two arguments and produces a double-valued result. |
public interface | ToDoubleFunction<
the type of the input to the function T>Represents a function that produces a double-valued result. |
public interface | ToIntBiFunction<
the type of the first argument to the function T, the type of the second argument to the function U>Represents a function that accepts two arguments and produces an int-valued result. |
public interface | ToIntFunction<
the type of the input to the function T>Represents a function that produces an int-valued result. |
public interface | ToLongBiFunction<
the type of the first argument to the function T, the type of the second argument to the function U>Represents a function that accepts two arguments and produces a long-valued result. |
public interface | ToLongFunction<
the type of the input to the function T>Represents a function that produces a long-valued result. |
public interface | UnaryOperator<
the type of the operand and result of the operator T>Represents an operation on a single operand that produces a result of the same type as its operand. |