当前位置:网站首页>On the fact that lambda expressions cannot handle recursion
On the fact that lambda expressions cannot handle recursion
2022-06-29 02:31:00 【Chuxin Java】
Why? lambda Expressions can't handle recursion ? because lambda The expression itself is a way to write anonymous functions , When the function name is omitted , It is more difficult to call yourself .
The reflection mechanism can be used to obtain Method Object recursively calls itself , But it's not necessary to be complicated .
When we want to solve a problem by recursion and don't want to write a separate method , We can use functional programming , but lambda Recursion of expression is troublesome , So we don't have to lambda The expression , While using lambda Degenerate version of expression - Anonymous inner class .
As shown in the following code , Use anonymous inner classes to compute factorials .
java.util.function.Function<Integer,Integer> func = new java.util.function.Function<Integer, Integer>(){
@Override
public Integer apply(Integer a) {
if(a==1){
return 1;
}
return a*apply(a-1);
}
};
System.out.println(func.apply(5));
边栏推荐
- [redis] sortedset type
- MySQL的下载和安装
- Which brokerage is safer and more convenient to open a stock account for big smart phones?
- The meaning of cross multiplication and dot multiplication (simple formula memory method)
- [redis] data introduction & General Command & string type
- Set set
- There is a time delay for the click event on the mobile terminal. What is the delay time? How to solve it?
- Learning Tai Chi Maker - mqtt Chapter II (IX) test of this chapter
- 音响是如何把微弱声音放大呢
- Mipi d-phy -- contents of HS and LP agreements
猜你喜欢

Install kibana

Has Moore's law come to an end?

Finally got the byte offer. The 25-year-old inexperienced experience in software testing is written to you who are still confused

They all talk about interviews with big factories. When I interview with small factories, I invite people to drink tea?
![[untitled]](/img/36/2f9319e05157ab6a8dd5aa3bef4505.png)
[untitled]

OpenResty 使用介绍

目标检测——ADAS实战

Koa 快速入门

Relationship between EMC, EMI and EMS

Oracle Recovery Tools实战批量坏块修复
随机推荐
月薪没到30K的程序员必须要背的面试八股,我先啃为敬
Google Borg论文
Dialogue with opensea co creation Alex: we still only touch the tip of the iceberg of NFT capability | chain catcher
【無標題】
字符串长度
温度转换 II
东方财富股票开户是会有什么风险吗?东方财富开户安全吗
Regular expression (?: pattern)
字符串方法练习
e.target与e.currentTarget的区别
Com3529 test analysis
B1006 output integer in another format
CTFHub-Web-SQL注入-整数型注入
Sysbench Pressure Test Oracle (installation and use examples)
String output
11 go Foundation: Interface
矩阵特征值和特征向量求解——特征值分解(EVD)
What is the dry goods microservice architecture? What are the advantages and disadvantages?
【学习笔记】子集和问题
Why should the pointer be null after delete