单身懒惰加载模式 [英] Singleton Lazy Loading Pattern
本文介绍了单身懒惰加载模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写Singleton Lazy Loading Pattern。这是类:
I am trying to write a Singleton Lazy Loading Pattern. Here is the class:
public class IMDBLookup {
private static class LazyLoad {
private static final IMDBLookup IMDB_LOOKUP;
static {
IMDB_LOOKUP = new IMDBLookup();
}
}
public static IMDBLookup getInstance() {
return IMDBLookup.LazyLoad.IMDB_LOOKUP;
}
}
我想知道我是否在做一个正确的方法?
I am wondering whether or not I am doing it in a right way?
提前致谢。
推荐答案
我更喜欢使用枚举简单。
I prefer to use enum for simplicity.
public enum IMDBLookup {
INSTANCE;
// add fields and methods here.
}
这篇关于单身懒惰加载模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文