Created
November 30, 2017 04:48
-
-
Save hishidama/7f391f44a4a54c6143ac4af7782db7d7 to your computer and use it in GitHub Desktop.
enumの相互参照
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
import java.util.function.Supplier; | |
public class EnumExample3 { | |
enum A { | |
A1(B.B1, () -> B.B1), A2(B.B2, () -> B.B2); | |
private B b; | |
private Supplier<B> s; | |
A(B b, Supplier<B> s) { | |
this.b = b; | |
this.s = s; | |
} | |
public B getB() { | |
return b; | |
} | |
public B getB2() { | |
return s.get(); | |
} | |
} | |
enum B { | |
B1(A.A1, () -> A.A1), B2(A.A2, () -> A.A2); | |
private A a; | |
private Supplier<A> s; | |
B(A a, Supplier<A> s) { | |
this.a = a; | |
this.s = s; | |
} | |
public A getA() { | |
return a; | |
} | |
public A getA2() { | |
return s.get(); | |
} | |
} | |
public static void main(String... args) { | |
for (A a : A.values()) { | |
System.out.printf("%s(%s %s)\n", a, a.getB(), a.getB2()); | |
} | |
for (B b : B.values()) { | |
System.out.printf("%s(%s %s)\n", b, b.getA(), b.getA2()); | |
} | |
} | |
} |
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
A1(B1 B1) | |
A2(B2 B2) | |
B1(null A1) | |
B2(null A2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment