开发者

Untargetted Bindings in Guice

开发者 https://www.devze.com 2023-02-18 00:56 出处:网络
In the Guice documentation, there is an Untargetted Binding example as: bind(MyConcreteClass.class) .annotatedWith(Names.named(\"foo\"))

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

精彩评论

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