Re: How to resolve bindings for unknown more specific parameterized types

41 views
Skip to first unread message

Tim Boudreau

unread,
Jun 6, 2013, 12:35:25 AM6/6/13
to google...@googlegroups.com
The bottom line is you have to explicitly bind things.  You could write something that iterates all the interfaces implemented by something and binds them all - but it's a recipe non-obvious problems when it blows up because two things resolve to the same type.  I tried having something called "bindPolymorphic()" for similar reasons some years ago, and it ended up being more trouble than it was worth.

-Tim

Tim Boudreau

unread,
Jun 7, 2013, 2:13:08 AM6/7/13
to google...@googlegroups.com
On Thursday, June 6, 2013 5:33:22 AM UTC-4, guillau...@gmail.com wrote:
Ok, thank you Tim. That's what I "feared" but I wanted to make sure I was not missing some feature here.

It's actually a really Good Thing[tm] that Guice doesn't try to do anything magical with types and polymorphism.  I think everyone bumps into something like this early on in using Guice and finds it a little annoying.  But later it turns out to be a blessing when something goes wrong and you're trying to sort it out, because you can safely assume that Guice is being pedantically literal in its interpretation of what you asked it to do.  Sometimes annoyingly so - as in binding X is not the same as binding X<?> - but it makes what it's going to do very predictable.

-Tim

Reply all
Reply to author
Forward
0 new messages