Quick Reference: Predefined Interfaces for Lambda Expression
At the time of writing, the java.util.function package provides 43 Interfaces to use with Lambda Expression and other purposes. Those predefined interfaces are often enough to cover common needs. While there are 43 of them, most are derivatives of the primary forms. For example, Consumer<T> has these derivatives:
BiConsumer<T,U>
DoubleConsumer
IntConsumer
LongConsumer
ObjDoubleConsumer<T>
ObjIntConsumer<T>
ObjLongConsumer<T>
Those Interfaces are different but their concept is the same. Given that the Interfaces can be organized into different concept groups, it is good to remember the primary form of each group. Here is a quick reference.
Consumer<T>
Abstract method: void accept(T t)
Accept an operation on an object of type T, and return no result.
Function<T,R>
Abstract method: R apply(T t)
Apply an operation to an object of type T, and return the result in type R.
Predicate<T>
Abstract method: boolean test(T t)
Evaluate if an object of type T satisfies a condition, and return the result in true or false.
Supplier<T>
Abstract method: T get()
By going through an operation, return the result of type T.
UnaryOperator<T>
Abstract method: T apply(T t)
Apply an operation to an object of type T, and return the result also in type T.
UnaryOpearator<T> is actually a sub-interface of Function<T,R> where T is the same as R.
BiConsumer<T,U>
DoubleConsumer
IntConsumer
LongConsumer
ObjDoubleConsumer<T>
ObjIntConsumer<T>
ObjLongConsumer<T>
Those Interfaces are different but their concept is the same. Given that the Interfaces can be organized into different concept groups, it is good to remember the primary form of each group. Here is a quick reference.
Consumer<T>
Abstract method: void accept(T t)
Accept an operation on an object of type T, and return no result.
Function<T,R>
Abstract method: R apply(T t)
Apply an operation to an object of type T, and return the result in type R.
Predicate<T>
Abstract method: boolean test(T t)
Evaluate if an object of type T satisfies a condition, and return the result in true or false.
Supplier<T>
Abstract method: T get()
By going through an operation, return the result of type T.
UnaryOperator<T>
Abstract method: T apply(T t)
Apply an operation to an object of type T, and return the result also in type T.
UnaryOpearator<T> is actually a sub-interface of Function<T,R> where T is the same as R.
Comments
Post a Comment