これは機能します:
public static class SomeGenericType<T> {
private TypeLiteral<T> type;
@Inject
public SomeGenericType(TypeLiteral<T> type) {
this.type = type;
}
public Class<? super T> getType() {
return type.getRawType();
}
}
Guiceは、次の場合に文字列を表すTypeLiteralを自動的に挿入します。
@Inject SomeGenericType<String> foo;
しかし、Assisted Injectで同じことを試みる場合:
public static interface FooFactory<T> {
Foo<T> create(String name);
}
public static class Foo<T> {
@AssistedInject
public Foo(TypeLiteral<T> type, @Assisted String name) {
....
私のモジュールは次のようになります:
public static class TestMod extends AbstractModule {
@Override
protected void configure() {
install(new FactoryModuleBuilder().build(new TypeLiteral<FooFactory<String>>(){}));
}
}
モジュールのインストール中に例外が発生します:
TypeLiteral<T> cannot be used as a Key, it is not fully specified.
私が注入しようとしているのは確かにTypeLiteralであり、それを削除すると汎用ファクトリが正常に機能するため、問題が発生します。
それで、私はおそらく今のところ自分の工場を転がすだけですが、これがうまくいくかどうか知りたいですか?FactoryModuleBuilderを少し異なる方法で使用することの問題ですか?