日期:2014-05-20 浏览次数:20971 次
class Test9 {
public static Test9 singleton = new Test9();
public static int a;
public static int b = 0;
public static int c = 2;
//public static Test9 singleton = new Test9();
……
}
对应字节码:
public class com.codetest.test.Test9 {
public static com.codetest.test.Test9 singleton;
public static int a;
public static int b;
public static int c;
static {};
Code:
0: new #17 // class com/codetest/test/Test9
3: dup
4: invokespecial #18 // Method "<init>":()V // 这里应该是调用构造函数
7: putstatic #5 // Field singleton:Lcom/codetest/test/Test9;
10: iconst_0
11: putstatic #3 // Field b:I // 这里对应 b = 0
14: iconst_2
15: putstatic #4 // Field c:I // 这里对应 c = 2
18: return
}