Annotation Type Multibinds

  • @Documented
    public @interface Multibinds
    Annotates abstract module methods that declare multibindings.

    You can declare that a multibound set or map is bound by annotating an abstract module method that returns the set or map you want to declare with @Multibinds.

    You do not have to use @Multibinds for sets or maps that have at least one contribution, but you do have to declare them if they may be empty.

       @Module abstract class MyModule {
         @Multibinds abstract Set<Foo> aSet();
         @Multibinds abstract @MyQualifier Set<Foo> aQualifiedSet();
         @Multibinds abstract Map<String, Foo> aMap();
         @Multibinds abstract @MyQualifier Map<String, Foo> aQualifiedMap();
         static Object usesMultibindings(Set<Foo> set, @MyQualifier Map<String, Foo> map) {
           return …

    A given set or map multibinding can be declared any number of times without error. Dagger never implements or calls any @Multibinds methods.

    See Also: