This is, of course, possible. Look at http://code.google.com/p/google-guice/wiki/FrequentlyAskedQuestions under "How to inject class with generic type?"
Am Donnerstag, 19. April 2012 02:47:09 UTC+2 schrieb Mirko Raner: > > Hi all, > > the Guice documentation for the Binder class states that "*Guice cannot > currently bind or inject a generic type, such as Set<E>; all type > parameters must be fully specified.*" > Is there any remedy for this limitation in sight? > > What I'm trying to do is the following: > A common source of unwanted coupling is introduced by using specific > implementations of collection types or other generic types, for example > > Map<String, Integer> elements = new HashMap<String, Integer>(); > > which ties the code to a specific implementation (HashMap, in this case). > Let's say that depending on my deployment scenario I might want to use GNU > Trove classes like THashMap instead. > However, rather than hard-coding the implementing class in my code, I > would like to write > > @Inject Map<String, Integer> elements; > > and have Guice take care of the rest. I obviously don't want to create > bindings specifically for maps from String to Integer, but for maps in > general. > There might also be additional annotations to specify implementation > preferences, for example > > @Inject @Identity Map<String, Integer> elements; // requires > IdentityHashMap or similar > @Inject @Synchronized @Linked Map<String, Integer> elements; // > requires a synchronized LinkedHashMap or similar > > Is support for features like this planned for a future release of Guice? > Or is there a way to do this already? > > Thanks, > > 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/-/hNeJpsG6SXsJ. 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.
