Suppose I have the following:
public class Foo<T> {
private final Class<T> tClass;
@Inject public Foo(Class<T> tClass) { this.tClass = tClass; }
}
I've heard that if tClass was instead a TypeLiteral, then I'd basically
have Foo<Integer>, Foo<String>, etc. for free. But suppose Foo is a
third-party class, and I wish to duplicate its effects. Since Class has no
automatic binding, I'm pretty much stuck with
bind(new TypeLiteral<Class<Integer>>(){}).toInstance(Integer.class);
Which has the drawback of, well, having to bind types that I know will be
used, leaving out unintended uses and such.
Now, it's probably possible, and even trivial, to implement a
Provider<Class<T>> for which, given a TypeLiteral<T> (where T is a
non-generic type), returns a Class<T>. However, I'm still stuck with
binding it in a non-generic manner.
Is there a workaround for this, so that I essentially have Foo<Integer>,
Foo<String>, etc., for free?
Also, would it be the same if instead tClass was MyCustomTypeTokenClass
(ie. not a TypeLiteral, but convertible from it)?
--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/8f0cc0af-1a38-4fbc-8f5b-e7470256039f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.