我刚开始学习如何使用 Guice,但在尝试配置辅助注射时遇到了一些麻烦。我有以下界面:
public interface Individual extends Comparable<Individual>, Iterable<Long>{ ... }
它将由工厂创建。构造函数必须接收一个长列表:
public interface IndividualFactory {
public Individual createIndividual(List<Long> chromossomes);
}
实现类有一个@Assisted 参数来接收列表:
public class IndividualImpl implements Individual {
@Inject
public IndividualImpl(
ConfigurationService configurationService,
RandomService randomService,
FitnessCalculatorService fitnessService,
@Assisted List<Long> chromossomes
) { ... }
最后,这是我的模块类:
public class SimpleModule extends AbstractModule {
@Override
protected void configure() {
bind(Individual.class).to(IndividualImpl.class);
install(new FactoryModuleBuilder().implement(Individual.class,
IndividualImpl.class).build(IndividualFactory.class));
}
问题是我运行项目时显示此错误:
1) No implementation for java.util.ArrayList<java.lang.Long> annotated with @com.google.inject.assistedinject.Assisted(value=) was bound.
while locating java.util.ArrayList<java.lang.Long> annotated with @com.google.inject.assistedinject.Assisted(value=)
for parameter 3 at implementation.entities.IndividualImpl.<init>(IndividualImpl.java:25)
at SimpleModule.configure(SimpleModule.java:36)
如果我只是删除辅助参数(不仅是注释,而且是参数本身)一切正常。我无法弄清楚我做错了什么。我遵循了我找到的所有 Guice 教程,但找不到使用 List<>; 的辅助参数示例;但是,即使我将此参数更改为整数,例如,我也会收到相同的错误。