Function函数有三个主要的方法:apply、compose、andThen
apply:该方法意义是执行当前函数的方法体。
compose(before):先执行before函数方法体,使用其返回参数,再执行调用者函数的方法体。
andThen(after):先执行调用者方法,将其返回值作为参数调用after函数方法体。
Function<Integer,Integer> multi= (a) -> a * 100 ;
Function<Integer,Integer> add = (a) -> a.intValue() + 10;
// 执行multi函数的方法体 1*100=100
System.out.println(multi.apply(1));
// 先执行add函数方法体 1+ 10 ,然后将其返回值11作为参数执行mutli的方法体,返回1100
System.out.println(multi.compose(add).apply(1));
// 先执行multi函数方法体 1*100,然后将其返回值100作为参数执行add的方法体,返回100
System.out.println(multi.andThen(add).apply(1));
输出结果
100
1100
110