inside JButton's actionperformed final variables required? [duplicate]
This question already has an answer here: Cannot refer to a non-final variable inside an inner class defined in a different method 20 answers So i have a JList and i am trying to use it inside of a JButton s actionPerformed method and it is asking me to make the JList final why is that, below is a code snippet public SomeClass() { btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { list.clearSelection(); }}); } I don't actually have a problem making it final, I just am not sure why i would need to. To answer your question, you need to understand