title: Performance of Java Enums?
body: <p>I am implementing a 2-player game that will be run in a tight loop literally hundreds of thousands of times, being then performance paramount.</p>
  
  <p>My code actually looks something like this:</p>
  
  <pre><code>public class Table {
      private final int WHITE_PLAYER = +1;
      private final int BLACK_PLAYER = -1;
  
      private final int currentPlayer;
      private final int otherPlayer;
  
      ...
  }
  </code></pre>
  
  <p>I was wondering if I would get any performance hit would I choose to replace</p>
  
  <pre><code>private final int WHITE_PLAYER = +1;
  private final int BLACK_PLAYER = -1;
  </code></pre>
  
  <p>to an enum defined as</p>
  
  <pre><code>public enum Players {
      WhitePlayer,
      BlackPlayer
  }
  </code></pre>
  
  <p>I had the idea that enums were just syntactic sugar over integer constants, and taking a glaze look over the bytecode generated for a test enum, as well as the code calling it, seems to indicate that using them is indeed the same as making a static method call but for some enum infrastructure that is set up when it's first run.</p>
  
  <p>Is my assumption that it is indeed the same to use enums as static constants correct or am I missing something here?</p>