Java Reference
In-Depth Information
Functional
interface
Function
descriptor
Primitive specializations
Predicate<T>
T -> boolean
IntPredicate, LongPredicate, DoublePredicate
Consumer<T>
T -> void
IntConsumer, LongConsumer, DoubleConsumer
Function<T, R>
T -> R
IntFunction<R>, IntToDoubleFunction, IntToLongFunction,
LongFunction<R>,
LongToDoubleFunction,
LongToIntFunction, DoubleFunction<R>, ToIntFunction<T>,
ToDoubleFunction<T>, ToLongFunction<T>
Supplier<T>
() -> T
BooleanSupplier, IntSupplier, LongSupplier, DoubleSupplier
UnaryOperator<T>
T -> T
IntUnaryOperator, LongUnaryOperator, DoubleUnaryOperator
BinaryOperator<T>
(T, T) -> T
IntBinaryOperator, LongBinaryOperator, DoubleBinaryOperator
BiPredicate<L, R>
(L,
R)
->
boolean
BiConsumer<T, U>
(T, U) -> void
ObjIntConsumer<T>,
ObjLongConsumer<T>,
ObjDoubleConsumer<T>
BiFunction<T, U, R>
(T, U) -> R
ToIntBiFunction<T,
U>,
ToLongBiFunction<T,
U>,
ToDoubleBiFunction<T, U>
You may already be wondering how lambda expressions are type checked. We detail how the
compiler checks whether a lambda is valid in a given context in section 3.5 . For now, it suffices
to understand that a lambda expression can be assigned to a variable or passed to a method
expecting a functional interface as argument, provided the lambda expression has the same
signature as the abstract method of the functional interface. For instance, in our earlier example,
you could pass a lambda directly to the process method as follows:
public void process(Runnable r){
r.run();
}
process(() -> System.out.println("This is awesome!!"));
 
Search WWH ::




Custom Search