[英]@Nullable doesn't seem to work with @AssistedInject
我有一個看起來像這樣的構造函數:
@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
知道有什么問題嗎? 我在這個問題上發現了另外兩個問題,其中一個說這是我不認為有的依賴關系問題 ,另一個說這是我確實使用過的Eclipse問題 ,但是我刷新,清理並重建了我的問題。 Maven從頭開始項目,所以我不確定是什么問題。
我正在使用javax.annotation.Nullable ,應該將其保留在運行時。 我還應該嘗試什么?
@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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.