我正在阅读以下新功能:http://www.javaworld.com/article/2078836/java-se/love-and-hate-for-java-8.html
我看到了下面的例子:
使用匿名类:
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.out.println("Action Detected");
}
});
Run Code Online (Sandbox Code Playgroud)
使用Lambda:
button.addActionListener(e -> {
System.out.println("Action Detected");
});
Run Code Online (Sandbox Code Playgroud)
MouseListener如果他们想在匿名类中实现多个方法,有人会做什么,例如:
public void mousePressed(MouseEvent e) {
saySomething("Mouse pressed; # of clicks: "
+ e.getClickCount(), e);
}
public void mouseReleased(MouseEvent e) {
saySomething("Mouse released; # of clicks: "
+ e.getClickCount(), e);
}
Run Code Online (Sandbox Code Playgroud)
... 等等?