什么线程正在初始化静态字段和静态块?从我的实验中我得出结论,它与“调用”线程相同,即
class Foo {
static {
System.err.printf("static {}: %s\n", Thread.currentThread());
}
}
public class Mini_StaticInitialization {
public static void main(final String[] args) {
System.err.printf("main: %s\n", Thread.currentThread());
new Foo();
}
}
输出
main: Thread[main,5,main]
static {}: Thread[main,5,main]
是否有任何限制或总是如此?