Created
March 28, 2013 18:20
-
-
Save wytten/5265580 to your computer and use it in GitHub Desktop.
Getting the "next" value of a Java enumeration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum Player { | |
SOUTH, WEST, NORTH, EAST; | |
public Player next() { | |
int index = (this.ordinal() + 1) % values().length; | |
return values()[index]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment