Thanks, Colin. You are raising a good point here, but the Maps were
just an example (and maybe a bad one). I guess it's debatable whether
the coupling to data structure implementations is a serious issue (but
it's still coupling, and I can imagine scenarios where it would cause
problems). I understand your point that "@Inject @Synchronized
@Identity Map map;" is almost as specific as creating an synchronized
IdentityHashMap, but still the injected variant provides flexibility
to exchange the implementation for a somehow optimized (Trove classes,
etc.) or maybe instrumented implementation. You don't have that
flexibility if you hard-code IdentityHashMap.
I see your point regarding collections, so it's probably a good idea
to move away from that example. In my opinion, type casts are one of
the biggest problems of type safety in Java, and I use generics
whenever possible to get rid of type casts. So, we're not only talking
about collections here, but any sort of application-specific generics.
For example, some customized storage or message class that can (type-
safely) contain different types of things. Or some other pervasive
mechanism in your application that requires different implementations
during testing and runtime, or when using remote or local storage (or
when running with different memory footprints).
Anyway, thanks for confirming that this is currently not possible in
Guice. Do you know of any intrinsic technical reason why this cannot
be supported, or is this simply the way the injector works right now
(but could be supported)?
As I mentioned in my other post, I was able to specify a binding of a
generic (i.e., <?>) TypeLiteral for an interface to a generic
TypeLiteral for its implementation class, but the binding seemed not
to have any effect for the injector.

Thanks,

Mirko

On Apr 19, 11:16 am, Colin Decker <[email protected]> wrote:
> 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

-- 
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