Hi there,

I'm new to Guice and I'm looking for a way to bind or inject Generic types 
which, extend a known type, but are themselves unknown at compile time. 

For example, given the a base generic type like: 

           class BaseGenericType{}

and the following derived types: 

    class GenericTypeA extends BaseGenericType{}
    class GenericTypeB extends BaseGenericType{}
    class GenericTypeC extends GenericTypeB{}


when someone registers a binding which has a generic parameter of a derived 
type 
    bind(new TypeLiteral<someInterface<GenericTypeC>>() {
        }).to(new TypeLiteral<someImplementation<GenericTypeC>>() {
        });

(in this case GenericTypeC extends GenericTypeB which extends 
BaseGenericType)  


I would like to automatically create a binding:
    bind(new TypeLiteral<myInterface<GenericTypeC>>() {
        }).to(new TypeLiteral<myImplementation<GenericTypeC>>() {
        }); 



here is the sudo code for what i'm looking to accomplish. 

if(type.getType() instanceof ParameterizedType)
{
Type[] genericTypes = ((ParameterizedType) 
type.getType()).getActualTypeArguments();
for(Type genericType: genericTypes)
{
    if (BaseGenericType.class.isAssignableFrom((Class<?>) genericType)) {

       
        TypeLiteral<myInterface<genericType>> typeLiteral = new 
TypeLiteral<myInterface<genericType>>();
        TypeLiteral<myImplementation<genericType>> typeLiteral2 = 
(TypeLiteral<myImplementation<genericType>>();

        bind(typeLiteral).to(typeLiteral2);
        
    }
}


Thanks for your help,
David

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to