Summary of 43 functions in Java 8, functional programming

Summary of 43 functions in Java 8

Based on the source code of Java8, this document is obtained by analyzing statistics and summarizing.

统计:
总共43个函数类
按函数的类别可分为5类
按参数个数可分为4类
按类型可以分为5类
继承关系:2个。大多数的函数类是没有继承关系的,仅仅靠类名称上的语义来保证关系的递进

1.5 types of functions

According to the class name, the keywords at the end are extracted and grouped to obtain 5 categories:

category quantity Summary describe method
Function 17 Function
BiFunction
type Function *3
type To type Function *6
To type Function *3
To type BiFunction *3
function.
1~2Parameters + 1return
R apply(T t);
R apply(T t, U u);
default compose(before);
default andThen(after);
static identity();
Consumer 8 Consumer
BiConsumer
type Consumer *3
Obj type Consumer *3
consumer.
1~2Parameters + 0return
void accept(T t);
void accept(T t, U u);
default andThen(after);
Operator 8 UnaryOperator
BinaryOperator
type UnaryOperator *3
type BinaryOperator *3
operate.
1~2Parameters + 1return
R apply(T t);
R apply(T t, U u);
int applyAsInt(int operand);
static identity();
static minBy(comparator);
static maxBy(comparator);
Predicate 5 Predicate
BiPredicate
DoublePredicate
IntPredicate
LongPredicate
Assertion, predicate.
1~2Parameters + 1return
boolean test(T t);
default and(other);
default negate();
default or(other);
static isEqual(targetRef);
Supplier 5 Supplier
BooleanSupplier
DoubleSupplier
IntSupplier
LongSupplier
provider.
0Parameters + 1return
T get();

2. 4 parameter categories

All functions are divided into 1-parameter and 2-parameter functions.

category quantity Summary describe method
none 4 Among the 5 basic categories, except Operator
Consumer, Function, Predicate, and Supplier
a parameter xxx(T t);
Bi 6 BiConsumer
BiFunction
BiPredicate
ToDoubleBiFunction
ToIntBiFunction
ToLongBiFunction
two parameters xxx(T t, U u);
Unary 4 UnaryOperator
DoubleUnaryOperator
IntUnaryOperator
LongUnaryOperator
Central operation R apply(T t);
static identity();
Binary 4 BinaryOperator
DoubleBinaryOperator
IntBinaryOperator
LongBinaryOperator
Binary operations R apply(T t, U u);
static minBy(comparator);
static maxBy(comparator);

2.1. The difference between “N parameters” and “N-element operation”:

N yuan the difference inheritance relationship
Unary Differences from functions: The parameters and return value types of unary operations must be the same; the parameters and return types of functions can be different UnaryOperator extends Function<T, T>
Binary Differences from 2-parameter functions: The two operands and return value types of binary operations must be the same; while 2-parameter functions do not have this requirement BinaryOperator extends BiFunction<T,T,T>

3. Type

Long 9
Int 9
Double 9
Obj 3 ObjDoubleConsumer ObjIntConsumer ObjLongConsumer
Boolean 1 BooleanSupplier
Help 4
ToInt 4
ToDouble 4

4、附录

原始的43个函数类,以及分解过程

编号 原始类名称 限定符1 限定符2 末尾
1 BiConsumer Bi Consumer
2 BiFunction Bi Function
3 BinaryOperator Binary Operator
4 BiPredicate Bi Predicate
5 BooleanSupplier Boolean Supplier
6 Consumer Consumer
7 DoubleBinaryOperator Double Binary Operator
8 DoubleConsumer Double Consumer
9 DoubleFunction Double Function
10 DoublePredicate Double Predicate
11 DoubleSupplier Double Supplier
12 DoubleToIntFunction Double ToInt Function
13 DoubleToLongFunction Double ToLong Function
14 DoubleUnaryOperator Double Unary Operator
15 Function Function
16 IntBinaryOperator Int Binary Operator
17 IntConsumer Int Consumer
18 IntFunction Int Function
19 IntPredicate Int Predicate
20 IntSupplier Int Supplier
21 IntToDoubleFunction Int ToDouble Function
22 IntToLongFunction Int ToLong Function
23 IntUnaryOperator Int Unary Operator
24 LongBinaryOperator Long Binary Operator
25 LongConsumer Long Consumer
26 LongFunction Long Function
27 LongPredicate Long Predicate
28 LongSupplier Long Supplier
29 LongToDoubleFunction Long ToDouble Function
30 LongToIntFunction Long ToInt Function
31 LongUnaryOperator Long Unary Operator
32 ObjDoubleConsumer Obj Double Consumer
33 ObjIntConsumer Obj Int Consumer
34 ObjLongConsumer Obj Long Consumer
35 Predicate Predicate
36 Supplier Supplier
37 ToDoubleBiFunction ToDouble Bi Function
38 ToDoubleFunction ToDouble Function
39 ToIntBiFunction ToInt Bi Function
40 ToIntFunction ToInt Function
41 ToLongBiFunction ToLong Bi Function
42 ToLongFunction ToLong Function
43 UnaryOperator Unary Operator

4.1 将拆分后的关键字分类

类型1 类型2 参数类型 函数类型
ToDouble Double Bi Consumer
ToInt Int Binary Function
ToLong Long Unary Operator
Obj Predicate
Boolean Supplier

Guess you like

Origin blog.csdn.net/booynal/article/details/129950762