title: Is it bad practice to use an Enum's ordinal value to index an array in Java?
body: <p>I have two arrays: Walls and Neighbors.</p>
  
  <pre><code>public boolean[] walls = new boolean[4];
  public Cell[] neighbors = new Cell[4];
  </code></pre>
  
  <p>and I have an Enum:</p>
  
  <pre><code>enum Dir
  {
      North,
      South,
      East,
      West
  }
  </code></pre>
  
  <p>Now, I would like to be able to access walls or neighbors by their direction, so I don't have to pass around a bunch of magic indexes.</p>
  
  <p>However, when I was reading the documentation for Enum.ordinal() it said that programmers will have almost no use for this method which made me think it shouldn't be used in this way.</p>
  
  <p>I was thinking of doing something like:</p>
  
  <pre><code>    List&lt;Dir&gt; availableDirections = new ArrayList&lt;Dir&gt;();
      for(Dir direction : Dir.values())
          if (!Neighbors[direction.ordinal()].Visited)
              availableDirections.add(direction);
  </code></pre>
  
  <p>or even:</p>
  
  <pre><code>return Neighbors[Dir.North.ordinal()];
  </code></pre>
  
  <p>Should I revert to using static constants for NORTH, SOUTH, EAST, WEST with the index value set to them or use an Enum's ordinal method?</p>