If you use the javap
with the -c
flag to disassemble the code, it will show you what is happening in the static block. It initializes the enum constants of your enum type.
static {};
Code:
0: new #1 // class test/Days
3: dup
4: ldc #20 // String MON
6: iconst_0
7: ldc #21 // String Monday
9: invokespecial #23 // Method "<init>":(Ljava/lang/String;ILjava/lang/String;)V
12: putstatic #27 // Field MON:Ltest/Days;
15: new #1 // class test/Days
18: dup
19: ldc #29 // String TUE
21: iconst_1
22: ldc #30 // String Thuesday
24: invokespecial #23 // Method "<init>":(Ljava/lang/String;ILjava/lang/String;)V
27: putstatic #32 // Field TUE:Ltest/Days;
30: new #1 // class test/Days
33: dup
34: ldc #34 // String WED
36: iconst_2
37: ldc #35 // String wedesday
39: invokespecial #23 // Method "<init>":(Ljava/lang/String;ILjava/lang/String;)V
42: putstatic #37 // Field WED:Ltest/Days;
45: new #1 // class test/Days
48: dup
49: ldc #39 // String THU
51: iconst_3
52: ldc #40 // String Thursday
54: invokespecial #23 // Method "<init>":(Ljava/lang/String;ILjava/lang/String;)V
57: putstatic #42 // Field THU:Ltest/Days;
60: new #1 // class test/Days
63: dup
64: ldc #44 // String FRI
66: iconst_4
67: ldc #45 // String Firday
69: invokespecial #23 // Method "<init>":(Ljava/lang/String;ILjava/lang/String;)V
72: putstatic #47 // Field FRI:Ltest/Days;
75: new #1 // class test/Days
78: dup
79: ldc #49 // String SAT
81: iconst_5
82: ldc #50 // String saturday
84: invokespecial #23 // Method "<init>":(Ljava/lang/String;ILjava/lang/String;)V
87: putstatic #52 // Field SAT:Ltest/Days;
90: new #1 // class test/Days
93: dup
94: ldc #54 // String SUN
96: bipush 6
98: ldc #55 // String Sunday
100: invokespecial #23 // Method "<init>":(Ljava/lang/String;ILjava/lang/String;)V
103: putstatic #57 // Field SUN:Ltest/Days;
106: bipush 7
108: anewarray #1 // class test/Days
111: dup
112: iconst_0
113: getstatic #27 // Field MON:Ltest/Days;
116: aastore
117: dup
118: iconst_1
119: getstatic #32 // Field TUE:Ltest/Days;
122: aastore
123: dup
124: iconst_2
125: getstatic #37 // Field WED:Ltest/Days;
128: aastore
129: dup
130: iconst_3
131: getstatic #42 // Field THU:Ltest/Days;
134: aastore
135: dup
136: iconst_4
137: getstatic #47 // Field FRI:Ltest/Days;
140: aastore
141: dup
142: iconst_5
143: getstatic #52 // Field SAT:Ltest/Days;
146: aastore
147: dup
148: bipush 6
150: getstatic #57 // Field SUN:Ltest/Days;
153: aastore
154: putstatic #59 // Field ENUM$VALUES:[Ltest/Days;
157: return