Skip to content

Commit 7917d5c

Browse files
committed
Add SingletonUtils
1 parent bae6530 commit 7917d5c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package cn.trinea.android.common.util;
2+
3+
/**
4+
* Singleton helper class for lazily initialization.
5+
*
6+
* @author <a href="http://www.trinea.cn/" target="_blank">Trinea</a>
7+
*
8+
* @param <T>
9+
*/
10+
public abstract class SingletonUtils<T> {
11+
private T instance;
12+
13+
protected abstract T newInstance();
14+
15+
public final T getInstance() {
16+
if (instance == null) {
17+
synchronized (SingletonUtils.class) {
18+
if (instance == null) {
19+
instance = newInstance();
20+
}
21+
}
22+
}
23+
return instance;
24+
}
25+
}

0 commit comments

Comments
 (0)