如何将参数传递给匿名类?
2022-08-31 07:32:00
是否可以将参数传递给匿名类或访问外部参数?例如:
int myVariable = 1;
myButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// How would one access myVariable here?
}
});
有没有办法让侦听器访问 myVariable 或传递 myVariable 而不将侦听器创建为实际的命名类?