我在以下位置阅读有关新功能的信息: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);
}
... 等等?