今天遇到一个关于线程的有趣的问题,做个记录。
首先是代码:
以上代码打印出的结果是什么的?
首先是代码:
public class Lazy {
public static boolean lazy = false;
static {
Thread thread = new Thread(new Runnable() {
public void run() {
System.out.println("befor...");
lazy = true;
System.out.println("after....");
}
});
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
System.out.println(lazy);
}
}
以上代码打印出的结果是什么的?