@Documented
@Retention(value=RUNTIME)
@Target(value=METHOD)
public @interface Binds
Module
that delegate bindings. For example, to
bind Random
to SecureRandom
a module could declare the
following: @Binds abstract Random bindRandom(SecureRandom secureRandom);
@Binds
methods are a drop-in replacement for Provides
methods that simply
return an injected parameter. Prefer @Binds
because the generated implementation is
likely to be more efficient.
A @Binds
method:
abstract
.
Provides
method)
and the parameter is the type to which it is bound.
For multibindings, assignability is checked in similar ways:
IntoSet
Set.add(E)
when viewed as a member of the return type — the parameter must be assignable to the
return type.
ElementsIntoSet
Set.addAll(java.util.Collection<? extends E>)
when viewed as a member of the return type — if the return type
is Set<E>
, the parameter must be assignable to Collection<? extends
E>
.
IntoMap
value
parameter of Map.put(K, V)
when viewed as a member of a Map
in which V
is bound to the return type — the parameter must be assignable to the return type