Set<E>; all type parameters must be
fully specified."Can't you simply do MyMap extends Map<String, Integer> and inject
that? Or create a wrapper with a getter and inject an instance of that
wrapper? Sure, it's a bit more work but how many different maps do you
need?
In fact, you should probably use MyMap directly (without extending
Map) so you can limit its API to exactly what you need. The exact map
implementation that it uses is then really just an implementation
detail (it need not even implement Map<String, Integer>).
This is, of course, possible. Look at http://code.google.com/p/google-guice/wiki/FrequentlyAskedQuestions under "How to inject class with generic type?"
TypeLiteral<List<String>> list = new TypeLiteral<List<String>>() {;}
http://google-guice.googlecode.com/git/javadoc/com/google/inject/Binder.html#bind(com.google.inject.TypeLiteral<T>)
Scala users should seriously consider using:
https://github.com/Deathbobomega/scala-guice
It will hide this pain inside Scala magic.
--
Thomas Suckow
> --
> You received this message because you are subscribed to the Google Groups "google-guice" group.
> To post to this group, send email to google...@googlegroups.com.
> To unsubscribe from this group, send email to google-guice...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
>
Pseudo Code:
TypeLiteral<Map<String, Integer>> literal = new
TypeLiteral<Map<String, Integer>>() {;}
bind(literal).annotatedWith(Identity.class).to(IdentityHashMap.class)
bind(literal).annotatedWith(SynchronizedLinked.class).to(SynchronizedLinkedHashMap.class)
--
Thomas Suckow
> --
> 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/-/YfM_xhqTIjcJ.
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.