swing_ui_thread

You need to use final for method parameters and local variables when you have a local inner class that needs to access the value. For example:

public void setText(final String str) {
    if (SwingUtilities.isEventDispatchThread())
        label.setText(str);
    else
        SwingUtilities.invokeLater(new Runnable()
        {
            public void run () {
                label.setText(str);  // final needed to use str here
            }
        });
}
The final modifier is needed in this case to guarantee that the value of str is consistent within both the inner class run() method and the setText() method. (The compiler actually copies the value of str into a field in the anonymous class and then uses the field from the anonymous class.)
Comments