java8 lambda
2022-02-20 21:44 tonyniu8 阅读(5) 评论(0) 编辑 收藏 举报runnable 为函数式接口。
所以支持下列写法。
public class LambdaExpression {
public static void process(Runnable r){
r.run();
}
public static void main(String[] args) {
Runnable r1 = () -> System.out.println("Hello World 1");
Runnable r2 = new Runnable(){
public void run(){
System.out.println("Hello World 2");
}
};
process(r1);
process(r2);
process(() -> System.out.println("Hello World 3"));
}
}