假设我有一个使用匕首注入的Singleton类
@Singleton
class SingletonClass {
@Inject
lateinit var newInstanceEveryTime: NewInstanceEveryTime
fun getNewInstance(): NewInstanceEveryTime {
return newInstanceEveryTime
}
}
[每当我使用SingletonClass.getNewInstance()调用方法getNewInstance()
时,我都需要每次获取新实例,但是我知道它不会每次都创建该实例,有人可以帮助我如何从中实现这一点。使用匕首的单例类。
@Singleton
class SingletonClass {
fun getNewInstance() = NewInstanceEveryTime()
}
但是您的用例是什么?为什么需要这种工厂方法?