Java 中 Lambda 表达式一共有五种基本形式,具体如下:
public static void main(String[] args) {
example4();
}
public static void examlpe1(){
Runnable r1 = ()-> System.out.println("hello world");
Thread t = new Thread(r1);
t.start();
}
public static void examlpe2(){
Function f = (name)-> System.out.println(name+"hello world");
f.getName("a");
}
public static void examlpe13(){
Runnable r1 = ()->{
System.out.println("hello world");
System.out.println("hello world2");
};
Thread t = new Thread(r1);
t.start();
}
public static void example4(){
BinaryOperator<Long> add = (Long x,Long y) -> x + y ;
System.out.println(add.apply(1L,2L));
}
public static void example5(){
BinaryOperator<Long> add = ( x, y) -> x + y ;
System.out.println(add.apply(1L,2L));
}
本文介绍了Java中Lambda表达式的五种基本形式,并通过具体的代码示例进行了解释,包括简单的Runnable实现、函数式接口的应用、多条语句的Lambda表达式及二元运算符的使用。
2088

被折叠的 条评论
为什么被折叠?



