开发者

Untargetted Bindings in Guice

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) { ... }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜