google-code-export / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
2 stars 1 forks source link

ConstantBindingBuilder should take Object #324

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Allow ConstantBindingBuilder to accept a Object, and use it's class as
type. Patch attached.

Original issue reported on code.google.com by mathias....@gmail.com on 6 Feb 2009 at 7:03

GoogleCodeExporter commented 9 years ago
Patch.

Original comment by mathias....@gmail.com on 6 Feb 2009 at 7:04

Attachments:

GoogleCodeExporter commented 9 years ago
Just use bind(...).annotatedWith(...).toInstance() which is much more explicit 
about the type being bound. With 
getClass(), there's a lot of problems since the runtime class may not be 
significant (such as anonymous inner 
classes, etc.)

Original comment by limpbizkit on 7 Feb 2009 at 1:31

GoogleCodeExporter commented 9 years ago
And then what in the case where you don't know the value class? Imagine this:

for (Map.Entry<String, Object> param :
action.getDefinition().getParamDefaultsMap().entrySet()) {

bind(param.getValue().getClass()).annotatedWith(Names.named(param.getKey())).toI
nstance(param.getValue());
}

Original comment by mathias....@gmail.com on 7 Feb 2009 at 1:33

GoogleCodeExporter commented 9 years ago
your example using plain bind() statements is sufficient. We don't really want 
to encourage folks to write 
bindings that they don't know statically.

Original comment by limpbizkit on 7 Feb 2009 at 5:01