1.形式一(只包含一个参数)
Actionlistener oneArgu = event -> System.out.println(“hello world”);
2.形式二(不含参数)
Runnable noArguments = () -> System.out.println(“hello world”);
3.形式三(主体是一个代码块)
Runnable multiStatement = () -> {
System.out.print(“Hello”);
System.out.println(" World");
};
4.形式三(包含多个参数)
BinaryOperator add = (x, y) -> x + y;
5.形式三(多个参数,并显示声明参数类型)
BinaryOperator addExplicit = (Long x, Long y) -> x + y;
Lambda表达式几种形式
最新推荐文章于 2022-10-31 18:10:26 发布