Suppose the code is:
public class Test {
public void test() {
JPanel panel = new JPanel();
int a;
JLabel label = new JLabel();
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
panel.setBackground(Color.BLACK); // Correct
a = 0; // Wrong, should be final
}
});
}
}
It confuses me that why I can access the JPanel
without a final
?