package com.xjtu;
public class MyLazyInitTest {
public static void main(String[] args) {
SingleLazy.test();
SingleLazy.getInstance();
AA.test();
}
}
class SingleLazy{
private SingleLazy(){};
private static class LazyHolder{
private static final SingleLazy SINGLE_LAZY = new SingleLazy();
static {
System.out.println("Lazy holder init!");
}
}
public static SingleLazy getInstance(){
return LazyHolder.SINGLE_LAZY;
}
public static void test(){
System.out.println("SingleLazy test!");
}
}
class AA{
static {
System.out.println("AA 初始化!");
}
public static void test() {
System.out.println("AA test!");
}
}
懒惰式的初始化
最新推荐文章于 2024-08-24 17:09:16 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)