title: Cannot refer to non-final variable and Timer
body: <p>I'm trying to write a static class which could change a background of control, which will be passed to the parameter. So I achieved this:</p>
  
  <pre><code>public static void wrong(final Component component) {
  
          component.setBackground(Color.RED);
          Timer   timer = new Timer(2, wrongAction);
  
          wrongAction = new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
  
                  int green = component.getBackground().getGreen();
                  int blue = component.getBackground().getBlue();
                  component.setBackground(new Color(255, green + 1, blue + 1));
                  if (component.getBackground() == Color.WHITE) {
                      timer.stop();
                  }
              }
          };
  
          timer.start();
  
      }  
  </code></pre>
  
  <p>And I've got a error:</p>
  
  <pre><code>Cannot refer to a non-final variable timer inside an inner class defined in a different method
  </code></pre>
  
  <p>of course, we can change timer to final, but method stops working after we do that.<br>
  I tried to google it and to find answer in other stackoverflow topics, but nothing helped me.</p>
  
  <p>Thanks a lot to everybody in advance! </p>