s-day07-Lambda表达式的简写形式

This commit is contained in:
2026-08-08 10:41:12 +08:00
parent 7db048bd7d
commit f39cedf7cd
3 changed files with 14 additions and 3 deletions
@@ -53,5 +53,7 @@ public class Demo01 {
new Thread(()->{
System.out.println(Thread.currentThread().getName()+"线程启动了");
}).start();
new Thread(()-> System.out.println(Thread.currentThread().getName()+"线程启动了")).start()
;
}
}
+3 -3
View File
@@ -21,11 +21,11 @@ public class Demo02 {
}
});*/
//使用lambda表达式简化以上代码
Collections.sort(students,(Student o1, Student o2)->{
/*Collections.sort(students,(Student o1, Student o2)->{
return o1.score-o2.score;
});
});*/
Collections.sort(students,(o1, o2)-> o2.score-o1.score);
System.out.println(students);
}
}
@@ -0,0 +1,9 @@
package com.inmind.lambda01;
/*
lambda表达式的省略语法:
1.参数列表()中的数据类型可以省略
2.如果(),参数列表中只有一个参数,并且数据类型已经省略,那么小括号也可以省略
3.如果{}中只有一条java语句,那么大括号,return,分号可以同时省略
*/
public class Demo03 {
}