A builder for a component. Components may have a single nested static abstract class or
interface annotated with
@ProductionComponent.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 (i.e., 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
ProductionComponent
with a builder:
@ProductionComponent(modules = {BackendModule.class, FrontendModule.class})
interface MyComponent {
ListenableFuture<MyWidget> myWidget();
@ProductionComponent.Builder
interface Builder {
MyComponent build();
Builder backendModule(BackendModule bm);
Builder frontendModule(FrontendModule fm);
}
}