@Binds is a more efficient and declarative mechanism for delegating a binding.


The problem

A @Provides or @Produces method that returns its single parameter has long been Dagger’s only mechanism for delegating a binding. Since the delegation is implemented via a user-defined method there is a disproportionate amount of overhead for such a conceptually simple operation. @Binds was introduced to provide a declarative way of delegating from one binding to another in a way that allows for minimal overhead in the implementation. @Binds should always be preferred over @Provides or @Produces for delegation.

For instance, the following @Provides method

@Provides static Heater provideHeater(ElectricHeater heater) {
  return heater;

is equivalent to the following preferred @Binds method.

@Binds abstract Heater bindHeater(ElectricHeater impl);


Suppress false positives by adding the suppression annotation @SuppressWarnings("UseBinds") to the enclosing element.