Possible Duplicate:
Cannot refer to a non-final variable inside an inner class defined in a different method
I'm just experimenting and have a question.
Why is this acceptable when I am accessing a non-final class variable from an anonymous inner class:
static JLabel e = new JLabel("");
public static void main(String[] args) {
JButton b = new JButton("ok");
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
String l = e.getText();
}
});
}
But the following is not acceptable without the final modifier: