I am not certain on the purpose for Dagger2\'s @Bind annotation.
From what i have read online im still not clear but here is an example:
@Module
pu
@Binds can be perfectly equivalent to a @Provides-annotated method like this:
@Provides
public HomePresenter provideHomePresenter() {
return new HomePresenterImp();
}
...though you'd probably prefer a variant that takes HomePresenterImp as a method parameter, which lets Dagger instantiate HomePresenterImp (assuming it has an @Inject constructor) including passing any dependencies it needs. You can also make this static, so Dagger doesn't need to instantiate your Module instance to call it.
@Provides
public static HomePresenter provideHomePresenter(HomePresenterImp presenter) {
return presenter;
}
So why would you choose @Binds instead? Dagger has a FAQ about it, but it boils down do these reasons:
static will also accomplish this, but your @Provides method will still compile if you forget the static. @Binds methods will not.Provider to a Provider and only keep one, rather than keeping one for HomePresenter that does nothing but call the one for HomePresenterImp.Thus, the entire thing would be well-represented as:
@Binds abstract HomePresenter bindHomePresenter(HomePresenterImp presenter);