On Thursday, April 19, 2012 3:57:26 AM UTC-7, Thomas Broyer wrote:
>
> On Thursday, April 19, 2012 12:30:27 PM UTC+2, Reinhard Nägele wrote:
>>
>> This is, of course, possible. Look at
>> http://code.google.com/p/google-guice/wiki/FrequentlyAskedQuestionsunder
>> "How to inject class with generic type?"
>
> Except that Mirko said: “I obviously don't want to create bindings
> specifically for maps from String to Integer, but for maps in general.”
>
Thanks, Thomas B., that was exactly my point! :-) Sorry that my original
question didn't really make it clear what I had in mind.
To clarify what I'm after: I would like to create a binding for the generic
version of a type, not for a concrete parameterized type.
If you look through your source code on a real-world project, you will
probably find hundreds of uses of java.util.Map, all of them parameterized
to different key and value type parameters. Right now, using Hilco and
Thomas S.'s suggestion, I would have to find all combinations of key/value
types and provide separate bindings for them. I don't want to create
bindings that are specific to the key/value types; I want to create a
binding for the general "Map" concept and specify a Map implementation that
is not bound to specific key/value types but is still generic.
The closest I can come expressing this in Guice is
binder.bind(new TypeLiteral<Map<?,?>>(){}).to(new
TypeLiteral<HashMap<?,?>>(){});
but that doesn't seem to work. If anyone knows how to achieve this kind of
binding that would be great (though I'm not very hopeful, as the Binder
documentation seems to say that it's not possible, if I understand it
correctly).
Thanks for any insights!
Mirko
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-guice/-/kmMO1_VDZ4oJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.