On Apr 19, 11:04 am, Mirko Raner <[email protected]> wrote:
> 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.

Sorry, another clarification -- apparently I'm really good at
confusing everyone ;-) :

The above binding of course DOES work for injections like @Inject
Map<?,?> map (with a wildcarded type), which makes sense. In line with
Java's type system this binding does not match any other injected
types (like Map<String, String>).
What I would really like to bind is Map<K,V> (with K and V being
unbound type parameters), but there is really no way to express that.
I tried binding raw types (i.e., TypeLiteral<Map> to
TypeLiteral<HashMap>, but (as expected) that binding only works for
raw types at the injection point.
I guess as part of solving this one would have to introduce special
"any" or "unbound" classes to be used for specifying the bindings: for
example, TypeLiteral<Map<Any,Any>>, or TypeLiteral<List<Unbound>>, or
maybe even something like TypeLiteral<Map<_,_>> or TypeLiteral<Map<$,
$>>.

I think at this point we all agree that Guice does not support this
use case. The follow-up questions, I guess, are: can it be implemented
and is it worth it?

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