In the Guice documentation, there is an Untargetted Binding example as:
bind(MyConcreteClass.class)
.annotatedWith(Names.named("foo"))
.to(MyConcreteClass.class);
Can someone explain, in plain English, what exactly this is doing and why y开发者_开发问答ou would want to do it?
It's creating a binding of type MyConcreteClass
annotated with @Named("foo")
using the implementation class MyConcreteClass
. You'd do it if you want to inject that type:
@Inject public Bar(@Named("foo") MyConcreteClass object) { ... }
精彩评论