This works:
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 automatically injects the TypeLiteral representing String when I do:
@Inject SomeGenericType<String> foo; But when trying the same thing with 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) { .... My Module looking like this:
public static class TestMod extends AbstractModule { @Override protected void configure() { install(new FactoryModuleBuilder().build(new TypeLiteral<FooFactory<String>>(){})); } } I get an exception while installing the module:
TypeLiteral<T> cannot be used as a Key, it is not fully specified. It's certainly the TypeLiteral that I'm trying to Inject that is the problem, as the generic factory does work fine when I remove it.
So, I'll probably just roll my own factory for the moment, but I'm curious to whether this should work? Is it a matter of using the FactoryModuleBuilder slightly differently?