我有一个看起来像这样的构造函数:
@Inject
public MyClass(
@Named("config") String configFile,
@Named("template") String templateFile,
CachedSettings settings,
@Assisted String channelId,
@Nullable @Assisted("NetworkA") NetworkInterface localNetworkInterfaceA,
@Nullable @Assisted("NetworkB") NetworkInterface localNetworkInterfaceB) {
我收到以下错误(两次,每个参数一次)
1) null returned by binding at my.company.package.MyClassFactory.create()
but parameter 4 of my.company.package.MyClass.<init>() is not @Nullable
while locating java.net.NetworkInterface annotated with @com.google.inject.assistedinject.Assisted(value=NetworkA)
for parameter 4 at my.company.package.MyClass.<init>(MyClass.java:24)
while locating my.company.package.MyClass annotated with interface com.google.inject.assistedinject.Assisted
知道出了什么问题吗?我在这个问题上发现了另外两个问题,其中一个说它是dependency issue,我认为我没有,另一个说它是Eclipse issue,我确实使用过,但我刷新了,从头开始清理和重建我的maven项目,所以我不确定是什么问题。
我正在使用javax.annotation.Nullable,它应该在运行时保留。我还应该尝试什么?
答案 0 :(得分:5)
@Nullable
。我们使用FactoryModuleBuilder
来声明我们的工厂。我正在粘贴适合我们的相关代码
@Inject
public AddressActions(EC2Service ec2Service,
RequestFactory requestFactory,
@Assisted("spiceManager") SpiceManager spiceManager,
@Assisted("parent") Context parent,
@Assisted("publicIp") @Nullable String publicIp) {
public static interface Factory {
AddressActions create(@Assisted("spiceManager") SpiceManager spiceManager,
@Assisted("parent") Context context,
@Assisted("publicIp") @Nullable String publicIp);
}
install(new FactoryModuleBuilder().build(AddressActions.Factory.class));
AddressActions actions = actionsFactory.create(spiceManager, getSherlockActivity(), null);
相关版本:
guice-3.0-no_aop.jar
guice-assistedinject-3.0.jar
jsr305-1.3.9.jar
-k