我正在阅读有关新功能的文章: 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");
}
});
对于 Lambda:
button.addActionListener(e -> {
System.out.println("Action Detected");
});
如果有人想在匿名类中实现多个方法,他们会用 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);
}
... 等等?