Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Java - hierarchy relationship in an enum
// From https://stackoverflow.com/questions/44654291/is-it-good-practice-to-use-ordinal-of-enum
public enum Person {
GRANDPARENT(null),
PARENT(GRANDPARENT),
CHILD(PARENT);
private final Person parent;
private Person(Person parent) {
this.parent = parent;
}
public final Parent getParent() {
return parent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment