Package dagger
Annotation Type Binds
-
@Documented @Retention(RUNTIME) @Target(METHOD) public @interface BindsAnnotates abstract methods of aModulethat delegate bindings. For example, to bindRandomtoSecureRandoma module could declare the following:@Binds abstract Random bindRandom(SecureRandom secureRandom);@Bindsmethods are a drop-in replacement forProvidesmethods that simply return an injected parameter. Prefer@Bindsbecause the generated implementation is likely to be more efficient.A
@Bindsmethod:- Must be
abstract. - May be scoped.
- May be qualified.
- Must have a single parameter whose type is assignable to the return type. The return type
declares the bound type (just as it would for a @
Providesmethod) and the parameter is the type to which it is bound.For multibindings, assignability is checked in similar ways:
IntoSet- The parameter must be assignable to the only parameter of
Set.add(E)when viewed as a member of the return type — the parameter must be assignable to the return type. ElementsIntoSet- The parameter must be assignable to the only parameter of
Set.addAll(java.util.Collection<? extends E>)when viewed as a member of the return type — if the return type isSet<E>, the parameter must be assignable toCollection<? extends E>. IntoMap- The parameter must be assignable to the
valueparameter ofMap.put(K, V)when viewed as a member of aMapin whichVis bound to the return type — the parameter must be assignable to the return type
- Must be