1.什么是this对象
this就是该对象实例本身
2.何为发布和逸出
发布,就是把对象暴露给他人,这就是为什么会需要用到封装,不能预料到其他第三方会如何使用对象,一不小心可能就被玩坏了
逸出,把不应该发布的对象发布了,就是逸出。比如对象还没完成实例化,就被外界使用了。
3.什么是构造过程中this引用逸出
public class Test {
private boolean isIt;
public Test() throws InterruptedException {
new Thread(new Runnable() {
public void run() {
System.out.println(isIt);
}
}).start();
Thread.sleep(2000L);
isIt = true;
}
public static void main(String[] args) throws InterruptedException {
Test test = new Test();
}
}
打印的结果是false,这个例子就是隐式的this对象引用逸出,还没有实例化完成时,其他线程就已经要用到对象中的属性
参考了stackoverflow上的文章,理解了什么是构造过程中this引用逸出。