当前位置:网站首页>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执行
边栏推荐
- Deep understanding of deepsea and salt deployment tools – storage6
- SUSE CEPH add nodes, reduce nodes, delete OSD disks and other operations – storage6
- 【深度学习】:《PyTorch入门到项目实战》第九天:Dropout实现(含源码)
- [deep learning]: introduction to pytorch to project practice: simple code to realize linear neural network (with code)
- 记录开发问题
- 结构化设计的概要与原理--模块化
- Best cow fences solution
- MD5 encryption verification
- 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?
- [deep learning]: day 4 of pytorch introduction to project practice: realize logistic regression from 0 to 1 (with source code)
猜你喜欢

Re11:读论文 EPM Legal Judgment Prediction via Event Extraction with Constraints
![[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)

Ugui learning notes (II) Scrollview related

Alibaba cloud MSE supports go language traffic protection

mysql 最大建议行数2000w,靠谱吗?

阿里云 MSE 支持 Go 语言流量防护

Easypoi multi sheet export by template
![[deep learning]: day 1 of pytorch introduction to project practice: data operation and automatic derivation](/img/4e/a41eee56fc0e8d3089f105bcb63155.png)
[deep learning]: day 1 of pytorch introduction to project practice: data operation and automatic derivation

飞马D200S无人机与机载激光雷达在大比例尺DEM建设中的应用

HTAP是有代价的
随机推荐
Games101 assignment04 job 04
Summary of kubenertes 1.16 cluster deployment problems
Unity shader uses rendered texture to achieve glass effect
kubenertes 1.16集群部署问题总结
向高通支付18亿美元专利费之后,传华为向联发科订购了1.2亿颗芯片!官方回应
Record the processing process of CEPH two RBDS that cannot be deleted
Using MVC in the UI of unity
海康威视回应'美国禁令'影响:目前所使用的元器件都有备选
leetcode647. 回文子串
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"
Given positive integers n and m, both between 1 and 10 ^ 9, n < = m, find out how many numbers have even digits between them (including N and m)
leetcode9. 回文数
Ugui learning notes (VI) get the information of the clicked UI
MySQL安装教程
Rsync 服务部署与参数详解
Ugui learning notes (IV) ugui event system overview and Usage Summary
[deep learning]: day 1 of pytorch introduction to project practice: data operation and automatic derivation
[deep learning]: introduction to pytorch to project practice: simple code to realize linear neural network (with code)
记录开发问题
做题笔记4(第一个错误的版本,搜索插入位置)