title: Performance of Java enums
body: <p>I was thinking about using <code>enum</code> type to manage i18n in a Java game I'm developing but I was curious about performance issues that can occur when working with enums that have lots of elements (thousands I think).</p>
  
  <p>Actually I'm trying something like:</p>
  
  <pre><code>public enum Text {
    STRING1,
    STRING2,
    STRING3;
  
    public String text() {
      return text;
    }
  
    public String setText() {
      this.text = text;
    }
  }
  </code></pre>
  
  <p>Then to load them I can just fill the fields:</p>
  
  <pre><code>static
  {
    Text.STRING1.setText("My localized string1"); 
    Text.STRING2.setText("My localized string2"); 
    Text.STRING3.setText("My localized string3"); 
  }
  </code></pre>
  
  <p>Of course when I'll have to manage many languages I'll load them from a file.</p>
  
  <p>What I'm asking is</p>
  
  <ul>
  <li>is an obect allocated (in addition to the string) for every element? (I guess yes, since enums are implemented with objects)</li>
  <li>how is the right element retrieved from the enum? is it static at compile time? (I mean when somewhere I use <code>Text.STRING1.text()</code>). So it should be constant complexity or maybe they are just replaced during the compiling phase..</li>
  <li>in general, is it a good approach or should I look forward something else?</li>
  </ul>
  
  <p>Thanks</p>