假设我有一个带有 @Inject 注释的 Student 类。
public class Student {
private String name;
private Integer age;
@Inject
public Student(String name, Integer age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
然后我有一个模块,在其中使用 @Provides 注释添加所有必需的依赖项。
@Module
public class StudentModule {
private String name;
private Integer age;
public StudentModule(String name, Integer age) {
this.name = name;
this.age = age;
}
@Provides
String provideName() {
return name;
}
@Provides
Integer provideAge() {
return age;
}
}
当然我还有 StudentComponent。
@Component(modules = {StudentModule.class})
public interface StudentComponent {
Student getStudent();
@Component.Builder
interface Builder {
@BindsInstance
Builder studentName(String studentName);
@BindsInstance
Builder studentAge(Integer studentAge);
StudentComponent build();
}
}
我想重写 Builder,以便将值传递给构建器本身,而不是模块。但每当我运行这个时,我都会收到错误:@Component.Builder is missing setters for required modules or components: [com.example.javadagger.StudentModule]
郎朗坤
相关分类