Context : java using guice (last version)
Hi everybody, is it possible to inject some TypeLiteral with Guice by this way :
In fact, I think it isn't possible. Generics are not reified at run-time. This means the information is not present at run-time. So it doesn't care what generic type you give it.
So, I think this method is not needed. Simply something like this:
public MyClass,?> getMyClass(Injector injector, Class> a, Class> b)
{
return new MyClass();
// Or maybe something like this, if you use custom constructors
// return injector.getInstance();
}
Since MyClass
is an interface, what you want to achieve is totally useless and impossible. How do you want to instantiate an object with a specific behavior when you only specify the param type and return type.
I think you should try to find a different way of working.