Personally, I don't think what you're trying to do (at least with the Maps)
is a very good idea. If you need an IdentityHashMap, create an
IdentityHashMap. You're basically trying to specify the exact type of Map
you want with annotations. What's that accomplishing for you? Do you really
need to be able to easily substitute a different type of Map for testing or
some such? In general, I'd avoid injecting things like data structures that
should be internal details of your class.

In any case, Guice doesn't support this.

-- 
Colin


On Thu, Apr 19, 2012 at 2:04 PM, Mirko Raner <[email protected]> wrote:

> 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/**FrequentlyAskedQuestions<http://code.google.com/p/google-guice/wiki/FrequentlyAskedQuestions>under
>>>  "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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
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.

Reply via email to