Java lambda 表达式

 

 

其实是试验一下markdown。。。

原:

只有一个抽象方法的接口称为函数式接口(functional interface)。

当需要实现了这种接口的类的对象的时候,就可以提供一个lambda表达式

lambda表达式的两种简单运用形式

1、

 
 
 
 
 
public class LambdaTest{
    public static void main(String[] args){
        Timer t = new Timer(1000 , event -> System.out.println("The time is " + new Date()));
        t.start();
        JOptionPane.showMessageDialog(null , "Quit program?");
        System.exit(0);
    }
}
 

2、

 
 
 
 
 
public class LambdaTest{
    public static void main(String[] args){
        ActionListener listener = event -> System.out.println("The time is " + new Date());
        Timer t = new Timer(1000 , listener);
        t.start();
        JOptionPane.showMessageDialog(null , "Quit program?");
        System.exit(0);
    }
}
 
posted @ 2017-01-12 22:16  xkfx  阅读(206)  评论(0)    收藏  举报