Skip to content

Instantly share code, notes, and snippets.

@Satomaru
Created November 30, 2017 05:48
Show Gist options
  • Save Satomaru/d2b479072c506e7b2768d792d051fb78 to your computer and use it in GitHub Desktop.
Save Satomaru/d2b479072c506e7b2768d792d051fb78 to your computer and use it in GitHub Desktop.
import java.util.function.Supplier;
public enum CircularReference {
P1(() -> Child.C1),
P2(() -> Child.C2);
public enum Child {
C1(P1),
C2(P2);
private final CircularReference parent;
private Child(CircularReference parent) {
this.parent = parent;
}
public CircularReference getParent() {
return parent;
}
}
private final Supplier<Child> supplier;
private CircularReference(Supplier<Child> supplier) {
this.supplier = supplier;
}
public Child getChild() {
return supplier.get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment