当前位置:网站首页>Function接口之andThen
Function接口之andThen
2022-07-28 16:13:00 【HelloWorld_Von】
Function 是一个函数式接口,andThen它的一个默认方法,就是在Function1执行后执行Function2。
源码:
/**
* Returns a composed function that first applies this function to
* its input, and then applies the {@code after} function to the result.
* If evaluation of either function throws an exception, it is relayed to
* the caller of the composed function.
*
* @param <V> the type of output of the {@code after} function, and of the
* composed function
* @param after the function to apply after this function is applied
* @return a composed function that first applies this function and then
* applies the {@code after} function
* @throws NullPointerException if after is null
*
* @see #compose(Function)
*/
default <V> Function<T, V> andThen(Function<? super R, ? extends V> after) {
Objects.requireNonNull(after);
return (T t) -> after.apply(apply(t));
}
代码:
Function<Integer, Integer> first=x ->x*x;
Function<Integer, Integer> after=y->y*2;
System.out.println(first.apply(3));
System.out.println(after.apply(3));
int res=first.andThen(after).apply(4);
System.out.println(res);
显示结果:
9
6
32
分析:
1.Function1-first 计算一个数的平方,3的平方9
2.Function2-after 计算一个数的2倍,3的两倍6
4.Function1.andThen 先是4的平方16,再16的2倍32.
结论:
f1.andThen(f2).apply(arg) f1执行后,f2执行
边栏推荐
- Best cow fences solution
- 给定正整数N、M,均介于1~10 ^ 9之间,N <= M,找出两者之间(含N、M)的位数为偶数的数有多少个
- go语言慢速入门——流程控制语句
- Realize the reset function of steering wheel UI with touch rotation and finger departure in unity
- Create a self-organizing / safe / controllable Lora network! Semtech responded for the first time to the impact of the "new regulations of the Ministry of industry and information technology"
- Leetcode70 suppose you are climbing stairs. You need n steps to reach the roof. You can climb one or two steps at a time. How many different ways can you climb to the roof?
- [JS] eight practical new functions of 1394-es2022
- Go language slow entry - process control statement
- [deep learning]: day 9 of pytorch introduction to project practice: dropout implementation (including source code)
- Unity shader uses rendered texture to achieve glass effect
猜你喜欢
![[deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)

Re10:读论文 Are we really making much progress? Revisiting, benchmarking, and refining heterogeneous gr

HTAP是有代价的

MySQL 5.7 and sqlyogv12 installation and use cracking and common commands

PostgreSQL每周新闻—2022年7月20日

Re12: read these3 semantic self segmentation for abstract summary of long legal documents in low

Unity3d shader achieves ablation effect

Tcp/ip related

ERROR: transport library not found: dt_ socket

College students participated in six Star Education PHP training and found jobs with salaries far higher than those of their peers
随机推荐
Epoll horizontal departure, which edge triggers
Rsync service deployment and parameter details
Unity shader screen post-processing
NoSQL introduction practice notes I
Leetcode70 suppose you are climbing stairs. You need n steps to reach the roof. You can climb one or two steps at a time. How many different ways can you climb to the roof?
Add differential pairs and connections in Ad
阿里云-武林头条-建站小能手争霸赛
Ugui learning notes (VI) get the information of the clicked UI
浏览器解码过程分析
kubenertes 1.16集群部署问题总结
概率论与数理统计第一章
给定正整数N、M,均介于1~10 ^ 9之间,N <= M,找出两者之间(含N、M)的位数为偶数的数有多少个
Global mobile communication base station market in 2019: Ericsson, Huawei and Nokia ranked in the top three
Ugui learning notes (IV) ugui event system overview and Usage Summary
After paying $1.8 billion in royalties to Qualcomm, Huawei reportedly ordered 120million chips from MediaTek! Official response
做题笔记2(两数相加)
epoll水平出发何边沿触发
[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)
结构化设计的概要与原理--模块化
MySQL安装教程