Skip to content

Commit 792d23b

Browse files
author
371718330@qq.com
committed
Singleton helper class for lazily initialization
1 parent 5167001 commit 792d23b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.jingewenku.abrahamcaijin.commonutil;
2+
3+
/**
4+
* @Description:主要功能:Singleton helper class for lazily initialization
5+
* @Prject: CommonUtilLibrary
6+
* @Package: com.jingewenku.abrahamcaijin.commonutil
7+
* @author: AbrahamCaiJin
8+
* @date: 2017年05月24日 18:17
9+
* @Copyright: 个人版权所有
10+
* @Company:
11+
* @version: 1.0.0
12+
*/
13+
14+
public abstract class SingletonUtils<T> {
15+
16+
private T instance;
17+
18+
protected abstract T newInstance();
19+
20+
public final T getInstance() {
21+
if (instance == null) {
22+
synchronized (SingletonUtils.class) {
23+
if (instance == null) {
24+
instance = newInstance();
25+
}
26+
}
27+
}
28+
return instance;
29+
}
30+
}

0 commit comments

Comments
 (0)