A builder for a component. Components may have a single nested static abstract class or
interface annotated with
@Component.Builder
. If they do, then the component's
generated builder will match the API in the type. Builders must follow some rules:
- A single abstract method with no arguments must exist, and must return the component.
(This is typically the
build()
method.)
- All other abstract methods must take a single argument and must return void,
the Builder type, or a supertype of the builder.
- Each component dependency must have an abstract setter method.
- Each module dependency that Dagger can't instantiate itself (e.g, the module
doesn't have a visible no-args constructor) must have an abstract setter method.
Other module dependencies (ones that Dagger can instantiate) are allowed, but not required.
- Non-abstract methods are allowed, but ignored as far as validation and builder generation
are concerned.
For example, this could be a valid Component with a Builder:
@Component(modules = {BackendModule.class, FrontendModule.class})
interface MyComponent {
MyWidget myWidget();
@Component.Builder
interface Builder {
MyComponent build();
Builder backendModule(BackendModule bm);
Builder frontendModule(FrontendModule fm);
}
}