当前位置:网站首页>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执行
边栏推荐
- Ruoyi集成flyway后启动报错的解决方法
- Brother Ali teaches you how to correctly understand the problem of standard IO buffer
- MD5 encryption verification
- Semtech推出物联网地理定位解决方案LoRa Edge,首款芯片LR1110现已上市
- Outline and principle of structured design -- modularization
- 关于 CMS 垃圾回收器,你真的懂了吗?
- [deep learning]: day 1 of pytorch introduction to project practice: data operation and automatic derivation
- 【深度学习】:《PyTorch入门到项目实战》第一天:数据操作和自动求导
- ERROR: transport library not found: dt_ socket
- In 2020q2, shipments in the global tablet market soared by 26.1%: Huawei ranked third and Lenovo increased the most!
猜你喜欢

浏览器解码过程分析

【深度学习】:《PyTorch入门到项目实战》第七天之模型评估和选择(上):欠拟合和过拟合(含源码)

Re11:读论文 EPM Legal Judgment Prediction via Event Extraction with Constraints

Realization of reflection and refraction effect in unity shader cube texture

Unity shader uses rendered texture to achieve glass effect

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

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

Comprehensively design an oppe homepage -- page service part
![[deep learning]: introduction to pytorch to project practice: simple code to realize linear neural network (with code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: introduction to pytorch to project practice: simple code to realize linear neural network (with code)

HTAP是有代价的
随机推荐
Leetcode647. Palindrome substring
epoll水平出发何边沿触发
HTAP comes at a price
Ugui learning notes (II) Scrollview related
Comprehensively design an oppe homepage -- page service part
How should I understand craft
Easypoi --- excel file export
负整数及浮点数的二进制表示
综合设计一个OPPE主页--页面的售后服务
Call DLL file without source code
Some suggestions on Oracle SQL tuning
Deep understanding of deepsea and salt deployment tools – storage6
[deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)
Question making note 3 (two point search)
Technology sharing | MySQL shell customized deployment MySQL instance
Unity shader transparent effect
充分利用----英文
Global mobile communication base station market in 2019: Ericsson, Huawei and Nokia ranked in the top three
mysql 最大建议行数2000w,靠谱吗?
Exercise note 5 (square of ordered array)