> Injecting local variables does not work. Guice injects fields, methods and
> constructors (if tagged with @Inject).
>
> So first, have your annotation represent that you will put it on fields or
> parameters:
>
> @Retention(RetentionPolicy.RUNTIME)
> @BindingAnnotation
> @Target({ElementType.FIELD, ElementType.PARAMETER})
> public @interface Apple { }
>
> Then, change your example to:
> FruitService apple = injector.getInstance(Key.get(FruitService.class,
> Apple.class));
>
> You should only need to get one object from the injector (top level object)
> directly. Others, lower down the object graph, you can simply @Inject:
> public class UsesService {
> @Inject
> public UsesService(@Apple FruitService service) { ... }
>
> }
>
> Hope this helps. Keep an eye out for my book! (
http://www.apress.com/book/view/1590599977)
>
> Robbie
>