title: Guice - How to use binding annotations to build a list of objects
body: <p>I have created Guice binding annotations that allow me to bind two different instances of a class depending on the annotation e.g.:</p>
  
  <pre><code>bind(Animal.class).withAnnotation(Cat.class).toInstance(new Animal("Meow"));
  bind(Animal.class).withAnnotation(Dog.class).toInstance(new Animal("Woof"));
  </code></pre>
  
  <p>I was hoping to be able to create a provider method that provides a List that is a dependency for one of my classes, but can't figure out how to use the annotations for this:</p>
  
  <pre><code>@Provider
  List&lt;Animal&gt; provideAnimalList() {
      List&lt;Animal&gt; animals = new ArrayList&lt;Animal&gt;();
      animals.add(@Cat Animal.class); // No, but this is what I want
      animals.add(@Dog Animal.class); // No, but this is what I want
      return animals;
  }
  </code></pre>
  
  <p>So I was assuming that I would just be able to use the annotations in the argument to <code>add()</code> method of the List... but no.</p>
  
  <p>How should I be approaching this? It seems to me it would be simpler simply to <code>new</code> the two instances of the Animal class and maybe this is not how the binding annotations were meant to be used.</p>
  
  <p>I'd appreciate comments on the best use of the binding annotations in this scenario.</p>
  
  <p>Thanks</p>