Dagger2 demo...
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.
build()
方法)案例
@Component(modules = {BackendModule.class, FrontendModule.class})
interface MyComponent {
MyWidget myWidget();
@Component.Builder
interface Builder {
//一个没有参数的`build()`方法,返回MyComponent类型
MyComponent build();
Builder backendModule(BackendModule bm);
Builder frontendModule(FrontendModule fm);
}
}
UserScope
用来规定User
对象再三个Activity中保持单例UserModule
和UserComponent
来实现Fruit
和两个子类Apple
和Pear
Fruit
类型的实例