【lambda系列——5种形式】
from java8函数式编程
package org.java8.lambda;
import java.awt.event.ActionListener;
import java.util.function.BinaryOperator;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class First {
public static void main(String[] args) {
Runnable noArguments = () -> System.out.println("Hello World");
//如果只有一个参数,可以把括号去掉
ActionListener oneArgument = event -> System.out.println("button clicked");
Runnable multiStatement = () -> {
System.out.print("Hello");
System.out.println(" World");
};
BinaryOperator<Long> add = (x, y) -> x + y;
BinaryOperator<Long> addExplicit = (Long x, Long y) -> x + y;
log.info("add: {} + {} = {}", 1L, 2L, add.apply(1L, 2L));
log.info("addExplicit: {} + {} = {}", 3L, 4L, addExplicit.apply(3L, 4L));
}
}