Skip to content

Commit

Permalink
Add SingletonUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinea committed May 28, 2014
1 parent bae6530 commit 7917d5c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/cn/trinea/android/common/util/SingletonUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cn.trinea.android.common.util;

/**
* Singleton helper class for lazily initialization.
*
* @author <a href="http://www.trinea.cn/" target="_blank">Trinea</a>
*
* @param <T>
*/
public abstract class SingletonUtils<T> {
private T instance;

protected abstract T newInstance();

public final T getInstance() {
if (instance == null) {
synchronized (SingletonUtils.class) {
if (instance == null) {
instance = newInstance();
}
}
}
return instance;
}
}

0 comments on commit 7917d5c

Please sign in to comment.