title: Java Enum Methods - return opposite direction enum
body: <p>I would like to declare an enum Direction, that has a method that returns the opposite direction (the following is not syntactically correct, i.e, enums cannot be instantiated, but it illustrates my point). Is this possible in Java?</p>
  
  <p>Here is the code: </p>
  
  <pre><code>public enum Direction {
  
       NORTH(1),
       SOUTH(-1),
       EAST(-2),
       WEST(2);
  
       Direction(int code){
            this.code=code;
       }
       protected int code;
       public int getCode() {
             return this.code;
       }
       static Direction getOppositeDirection(Direction d){
             return new Direction(d.getCode() * -1);
       }
  }
  </code></pre>