Skip to main content
3 of 3
added 1 character in body
user avatar
user avatar

Try this.

public enum Direction { UP, RIGHT, DOWN, LEFT; private 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 
user17233545