title: In Java how can I access a variable from outside the anonymous class
body: <p>for example:</p>
  
  <pre><code>for (int i = 0; i &lt; 10; i++){
     SomeClass something = new SomeClass();
     something.setOnClickListener(new OnClickListener() {
        public void onClick(){
           doSomething(i);
        }
     });
  }
  </code></pre>
  
  <p>I am not allowed to use the variable <code>i</code>, Eclipse suggest me make the <code>i</code> <code>final</code>, but I cannot do that because I need it to iterate right?</p>