Created
July 17, 2021 09:41
-
-
Save ourmaninamsterdam/206ab4ab90a89bc5b67504c345ab436f to your computer and use it in GitHub Desktop.
Java - hierarchy relationship in an enum
This file contains hidden or 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
// 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