Try this.
public enum Direction { UP, RIGHT, DOWN, LEFT; publicprivate static final Direction[] VALUES = values(); public Direction next() { return VALUES[(ordinal() + 1) % VALUES.length]; } } public static void main(String[] args) { Direction a = Direction.LEFT; Direction b = Direction.UP; System.out.println(a.next() == b); } output:
true