title: How is values() implemented for Java 6 enums?
body: <p>In Java, you can create an enum as follows:</p>
  
  <pre><code>public enum Letter {
      A, B, C, D, E, F, G;
  
      static {
         for(Letter letter : values()) {
            // do something with letter
         }
      }
  }
  </code></pre>
  
  <p>This question concerns the "values()" method. Specifically, how is it implemented? Usually, I could jump to the source for Java classes using F3 or CTRL+Click in Eclipse (even for classes like String, Character, Integer, and even Enum). It is possible to view the source of the other enum methods (e.g., valueOf(String)).</p>
  
  <p>Does "values()" create a new array each time it is invoked? If I assign it to a local variable and then modify one of the elements, what happens (clearly this won't affect the value returned by values(), which implies that a new array is allocated each time).</p>
  
  <p>Is the code for it native? Or does the JVM / compiler treat it specially, only returning a new instance from values() when it cannot prove that it will not be modified.</p>