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));
}