java基础之弱引用
弱引用
弱引用是指使用 WeakReference
且WeakReference并没有实现get方法,因此弱引用无法获得强引用对象。
代码演示
public class WeakReferenceTest {
public static void main(String[] args) {
WeakReference<M> mWeakReference = new WeakReference<>(new M());
System.out.println(mWeakReference.get());
System.gc();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(mWeakReference.get());
}
}
本文来自博客园,作者:King-DA,转载请注明原文链接:https://www.cnblogs.com/qingmuchuanqi48/articles/17465466.html

浙公网安备 33010602011771号