title: Why can't I hold EnumMap entries via a "for" loop, even if I use "final"? Best workaround?
body: <p>I'm having some strange behaviour.</p>
  
  <p>[UPDATE: Full runnable example given:]</p>
  
  <pre><code>package finaltestwithenummapentry;
  
  import java.util.ArrayList;
  import java.util.EnumMap;
  import java.util.Map.Entry;
  
  public class FinalTestWithEnumMapEntry {
  
      enum SomeEnum{
          ONE, TWO, THREE;
      }
  
      public static void main(String[] args) {
          EnumMap&lt;SomeEnum, Integer&gt; map = new EnumMap&lt;SomeEnum, Integer&gt;(SomeEnum.class);
          map.put(SomeEnum.ONE, 1);
          map.put(SomeEnum.TWO, 2);
          map.put(SomeEnum.THREE, 3);
  
          ArrayList&lt;Entry&lt;SomeEnum, Integer&gt;&gt; entryList = new ArrayList&lt;Entry&lt;SomeEnum, Integer&gt;&gt;();  
  
          for(final Entry&lt;SomeEnum, Integer&gt; entry : map.entrySet()){      
              System.out.println("Key is " + entry.getKey() + ", value is " + entry.getValue());     
              //This prints the correct keys and values      
  
              entryList.add(entry); 
          }  
  
          System.out.println("");
  
          for(Entry&lt;SomeEnum, Integer&gt; entry:entryList){     
              System.out.println("Key is " + entry.getKey() + ", value is " + entry.getValue());     
              //This prints only the last entry each time 
          }
      }
  }
  </code></pre>
  
  <p>Output (JavaSE 1.6):</p>
  
  <pre><code>Key is ONE, value is 1
  Key is TWO, value is 2
  Key is THREE, value is 3
  
  Key is THREE, value is 3
  Key is THREE, value is 3
  Key is THREE, value is 3
  </code></pre>
  
  <p>My <code>entry</code>, which I'm presuming is final, is seemingly overwritten by the next one each time. I need to be able to capture the correct entry each time, as I am passing each item to an anonymous inner class instance inside the <code>for</code> loop.</p>
  
  <p>[UPDATE: This problem doesn't exist in Java 7, only Java 6 (and maybe before) ]</p>
  
  <p>UPDATE:
  I might have to make my code work whether it's compiled against Java 6 or 7, so what's the most efficient workaround for making it work in either case?</p>