当前位置:网站首页>Several simplified forms of lambda expression
Several simplified forms of lambda expression
2022-07-05 00:28:00 【ZZYSY~】
For a functional interface ( There is only one method interface ), We can use lambda Expression to realize its , Here's how to use lambda Several simplified forms of expression
- Conventional form ( There are parameter types , There are brackets , There are curly braces. )
public class lamda {
public static void main(String[] args) {
Hello like = (int i)->{
System.out.println("hello" + i);
};
like.hello(5);
}
}
interface Hello {
void hello(int i);
}
- Simplified parameter type
For methods that have no parameters or one parameter :
Can be simplified
public class lamda {
public static void main(String[] args) {
Hello like = (i)->{
System.out.println("hello" + i);
};
like.hello(5);
}
}
interface Hello {
void hello(int i);
}
For methods with multiple parameters :
To simplify , All simplified
public class lamda {
public static void main(String[] args) {
Hello like = (i,j)->{
System.out.println("hello" + i + j);
};
like.hello(5,"world");
}
}
interface Hello {
void hello(int i,String j);
}
- Simplified brackets
For methods that have no parameters or one parameter :
Can be simplified
public class lamda {
public static void main(String[] args) {
Hello like = i->{
System.out.println("hello" + i);
};
like.hello(5,);
}
}
interface Hello {
void hello(int i);
}
For methods with multiple parameters :
Irreducible parentheses 
- Simplify curly braces
For methods with only one line of code :
Can be simplified
public class lamda {
public static void main(String[] args) {
Hello like = (i,j)->System.out.println("hello" + i + j);
like.hello(5,"world");
}
}
interface Hello {
void hello(int i,String j);
}
For methods with multiple lines of code :
Do not simplify curly braces 
summary :
- The premise is that the interface is functional ( There is only one method interface )
- All the above simplified forms can be used together , That is, the parameter type can be simplified , You can also simplify parentheses
- lambda An expression can only be simplified to one line if it has only one line of code , If there are many lines , Then wrap it in code blocks .
- Multiple parameters can also be swept parameter types , If you want to get rid of everything , It has to be bracketed
边栏推荐
- Tester's algorithm interview question - find mode
- What did I pay for it transfer to testing post from confusion to firmness?
- js如何实现数组转树
- 【雅思阅读】王希伟阅读P4(matching1)
- 人生无常,大肠包小肠, 这次真的可以回家看媳妇去了。。。
- Get to know ROS for the first time
- If you open an account of Huatai Securities by stock speculation, is it safe to open an account online?
- 人脸识别5- insight-face-paddle-代码实战笔记
- [IELTS reading] Wang Xiwei reading P3 (heading)
- TS快速入门-函数
猜你喜欢

Using fast parsing intranet penetration to realize zero cost self built website

圖解網絡:什麼是網關負載均衡協議GLBP?
![[selenium automation] common notes](/img/d3/6699792e85b5ee5a2d6192f4e4d07c.png)
[selenium automation] common notes

巩固表达式C# 案例简单变量运算

Data on the number of functional divisions of national wetland parks in Qinghai Province, data on the distribution of wetlands and marshes across the country, and natural reserves in provinces, cities

Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet

How many triangles are there in the golden K-line diagram?

图解网络:什么是网关负载均衡协议GLBP?

雅思考试流程、需要具体注意些什么、怎么复习?

lambda表达式
随机推荐
Two numbers replace each other
(script) one click deployment of any version of redis - the way to build a dream
如何避免电弧产生?—— AAFD故障电弧探测器为您解决
Detailed explanation of openharmony resource management
P4281 [ahoi2008] emergency assembly / gathering (LCA)
Fs8b711s14 electric wine bottle opener MCU IC scheme development special integrated IC
Is it safe to open an account in the College of Finance and economics? How to open an account?
The pit of sizeof operator in C language
IT转测试岗,从迷茫到坚定我究竟付出了什么?
lambda expressions
【路径规划】RRT增加动力模型进行轨迹规划
What did I pay for it transfer to testing post from confusion to firmness?
[monitoring] ZABBIX
Complete knapsack problem (template)
Application of fire fighting system based on 3D GIS platform
GDB常用命令
Multilingual Wikipedia website source code development part II
(脚本)一键部署redis任意版本 —— 筑梦之路
Summary of week 22-07-02
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?