Different @Singleton & static @Provides in dagger2

前端 未结 2 1018
小蘑菇
小蘑菇 2021-01-31 10:35

May I know the different between @Singleton VS static Provides in dagger2?

@Provides static User currentUser(AuthManager authMa         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-31 11:16

    With @Singleton annotation only one instance of User object will be created throughout the application lifecycle.

    static on @Provides methods introduced recently to make the invocation of method faster by 15 to 20% as mentioned here. There will be multiple instances of User object if we call this method multiple times.

提交回复
热议问题