publicclassHelloWorld{privatestaticbooleaninitialized=false;staticThreadt=newThread(newRunnable(){publicvoidrun(){System.out.print(initialized);//labelSystem.out.print(...
public class HelloWorld {
private static boolean initialized = false;
static Thread t = new Thread(new Runnable() {
public void run() {
System.out.print(initialized); //label
System.out.print("Hello ");
initialized = true;
}
});
static{
t.start();
try{
t.join();
}catch (InterruptedException e){
throw new AssertionError(e);
}
}
public static void main(String[] args){
System.out.println(" world!");
}
}
谁能解释下这段代码的执行流程?静态块是在MAIN()之前就运行了吧??为甚吗去掉Label处代码可以打印出Hello,而添上Label处代码就什么都不显示 一直在等待状态? 谢谢
越详细 越好!!~!
展开