@Documented @Target(value=TYPE) @Beta public @interface Multibindings
You can declare that a multibound set or map is bound by nesting a
@Multibindings
-annotated interface within a module, with methods that return the sets or
maps you want to declare.
You do not have to use @Multibindings
for sets or maps that have at least one
contribution, but you do have to declare them if they may be empty.
@Module
class MyModule {
@Multibindings
interface MyMultibindings {
Set<Foo> aSet();
@MyQualifier Set<Foo> aQualifiedSet();
Map<String, Foo> aMap();
@MyQualifier Map<String, Foo> aQualifiedMap();
}
@Provides
static Object usesMultibindings(
Set<Foo> set, @MyQualifier Map<String, Foo> map) {
return …
}
}
All methods on the interface and any supertypes (except for methods on Object
) are
used to declare multibindings. The names of the interface and its methods are ignored. A given
set or map multibinding can be declared any number of times without error. Dagger never
implements the interface or calls any of its methods.
Copyright © 2012���2017 The Dagger Authors. All rights reserved.