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