单例池,再也不用在每个单例类里面写 sInstance 了
- 添加仓库
maven { url 'https://www.jitpack.io' }
- 导入 SDK
implementation 'com.github.niulinguo:InstancePoolSDK:v1.1'
- 注册单例
InstancePool.register(DbManager.class, new InstanceCreator<DbManager>() {
@Override
public DbManager createInstance() {
return new DbManager();
}
});
- 获取单例
DbManager dbManager = InstancePool.get(DbManager.class);