当前位置:网站首页>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));
边栏推荐
- 字符串方法练习
- Learning Tai Chi Maker - mqtt Chapter II (IX) test of this chapter
- Google Borg paper
- 字符串替换
- 安装kibana
- Application of fsockopen function
- apache不解析PHP文件,直接显示源码
- 安装mysql5.7 并修改密码
- What is Mipi
- [MySQL practice of high concurrency, high performance and high availability of massive data -9] - transaction concurrency control solutions lbcc and mvcc
猜你喜欢

Use code binding DataGridView control to display tables in program interface

Zhongyi technology resumed the review status of the gem IPO, and xuxiaofei no longer acted as a practicing lawyer

Download and installation of MySQL
![[redis] hash type](/img/8b/2585908318f5fe88b455323d3f392e.png)
[redis] hash type

目标检测——ADAS实战

To apply for a test engineer after years, the resume with high scores should be written like this

【Redis】数据介绍 & 通用命令 & String类型

What is the dry goods microservice architecture? What are the advantages and disadvantages?

They all talk about interviews with big factories. When I interview with small factories, I invite people to drink tea?

thinkphp5.1 runtime文件改成777权限了, 还是无法写入
随机推荐
Ctfhub web password weak password
[redis] sortedset type
String attribute exercise
三角函数计算
项目研发,有哪些好用的免费脑图工具软件
Some tests on complementary wasm environment
thinkphp5.1 runtime文件改成777权限了, 还是无法写入
"The first share of endoscope" broke into IPO two times. Last year, it lost 500million yuan. The commercialization of core products is still in doubt | IPO Express
China's flexible employment has reached 200million
温度转换 II
干货丨微服务架构是什么?有哪些优点和不足?
To apply for a test engineer after years, the resume with high scores should be written like this
字符串属性练习
[learning notes] subsets and questions
Smart world 2030
正则表达式(?:pattern)
短视频平台常见SQL面试题,你学会了吗?
Which brokerage is safer and more convenient to open an account for compass mobile stock?
Introduction to openresty
Chrome browser close update Popup