首页 > 其他分享 >Initialization-on-demand holder idiom 单例

Initialization-on-demand holder idiom 单例

时间:2023-01-12 11:09:41浏览次数:54  
标签:LazyHolder Initialization private idiom static Something 单例 holder


在​​wikipedia​​中看到一种单例,效果不错,分享一下。

public class Something {
private Something() {}

private static class LazyHolder {
static final Something INSTANCE = new Something();
}

public static Something getInstance() {
return LazyHolder.INSTANCE;
}
}


参考:

​http://ifeve.com/initialization-on-demand-holder-idiom/​

标签:LazyHolder,Initialization,private,idiom,static,Something,单例,holder
From: https://blog.51cto.com/u_15939105/6003836

相关文章