英文:
Set null to Dagger Singleton object
问题
If in class1
I set an object that is Injected with Dagger and is @Singleton
to null. And in class2
I Inject that object again.
Is the object null or will it be provided from the module again?
英文:
If in class1
I set an object that Injected with Dagger and is @Singleton
to null. And in class2
I Inject that object again.
Is the object null or it will provide from module again?
答案1
得分: 0
Scoped dependencies (@Singleton
in this case) are only generated once per Component instance and then re-used for any future injections. If you are using the same instance of your Component in class1
and class2
, they'll get the same object, regardless of whether or not you nullify references to that object.
英文:
Scoped dependencies (@Singleton
in this case) are only generated once per Component instance and then re-used for any future injections.<br/>
So if you are using the same instance of your Component in class1
and class2
, they'll get the same object, regardless of whether or not you nullify references to that object.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论