进阶day06-Lambda表达式的简写形式
This commit is contained in:
@@ -45,5 +45,9 @@ public class Demo01 {
|
||||
}).start();
|
||||
//-------------------------------以下使用函数式编程思想优化以上的代码(lambda)----------------------------------
|
||||
new Thread(()->{ System.out.println(Thread.currentThread().getName()+"线程启动了");}).start();
|
||||
//以下代码中方法体只有一条java语句,省略了大括号,分号
|
||||
new Thread(()->System.out.println(Thread.currentThread().getName()+"线程启动了")).start();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ public class Demo02 {
|
||||
}
|
||||
});*/
|
||||
|
||||
Collections.sort(students,(Student o1, Student o2)->{ return o2.score - o1.score;});
|
||||
// Collections.sort(students,(Student o1, Student o2)->{ return o2.score - o1.score;});
|
||||
Collections.sort(students,(o1, o2)-> o2.score - o1.score);
|
||||
|
||||
System.out.println(students);
|
||||
}
|
||||
|
||||
12
javaSE-day07/src/com/inmind/lambda01/Demo03.java
Normal file
12
javaSE-day07/src/com/inmind/lambda01/Demo03.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.inmind.lambda01;
|
||||
/*
|
||||
lambda表达式的省略语法:
|
||||
1.参数列表()中的数据类型可以省略
|
||||
2.如果(),参数列表中只有一个参数,并且数据类型已经省略,那么小括号也可以省略
|
||||
3.如果{}中只有一条java语句,那么大括号,return,分号可以同时省略
|
||||
*/
|
||||
public class Demo03 {
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user