title: Java Guice - guice equivalent way to create multiple 'beans' like in Spring?
body: <p>Does Guice have a way to simply let me create multiple objects/beans with different values/parameters? 
  For example let say I have <code>Triangle</code> class and I want in configuration to create multiple triangles, one with parameter <code>lengh = 6</code>, one with <code>length = 5</code> and let say another without parameters at all.
  If I try something like this:</p>
  
  <pre><code>bind(Triangle.class).to(IsoTriangle.class);
  bind(Triangle.class).toInstance(new Triangle(6));
  </code></pre>
  
  <p>I get error:</p>
  
  <p><code>A binding to test.Triangle was already configured at test.Configuration.configure(Configuration.java:14).
    at test.Configuration.configure(Configuration.java:15)</code></p>
  
  <p>If I try to call two Triangle instances in main method like:</p>
  
  <pre><code>Triangle tr = injector.getInstance(Triangle.class);
  Triangle tr2 = injector.getInstance(Triangle.class);
  </code></pre>
  
  <p>Second instance is just ignored, as I don't see it being used second time.</p>
  
  <p>I read that there is something like this:</p>
  
  <pre><code>class LegModule extends PrivateModule {
    private final Class&lt;? extends Annotation&gt; annotation;
  
    LegModule(Class&lt;? extends Annotation&gt; annotation) {
      this.annotation = annotation;
    }
  
    @Override protected void configure() {
      bind(Leg.class).annotatedWith(annotation).to(Leg.class);
      expose(Leg.class).annotatedWith(annotation);
  
      bindFoot();
    }
  
    abstract void bindFoot();
  }
    public static void main(String[] args) {
      Injector injector = Guice.createInjector(
          new LegModule(Left.class) {
            @Override void bindFoot() {
              bind(Foot.class).toInstance(new Foot("leftie"));
            }
          },
          new LegModule(Right.class) {
            @Override void bindFoot() {
              bind(Foot.class).toInstance(new Foot("righty"));
            }
          });
    }
  </code></pre>
  
  <p>But it looks more like a trick/hack (do you need to do this kind of stuff in main method. Like in spring you don't need to do anything in main at all. But I suppose ideas for these frameworks are quite different). Does Guice have simpler way to do this or Guice purpose is to bind everything to one instance and don't let creating multiple same type objects?..</p>
  
  <p><strong>Update</strong>
  In spring it is straight forward:
  For example to create multiple triangles I can just do this:</p>
  
  <pre><code>&lt;bean id="triangle1" 
      class="test.Triangle"
      &gt;
      &lt;constructor-arg type="int" value="6"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="triangle2" 
      class="test.Triangle"
      &gt;
      &lt;constructor-arg type="int" value="5"/&gt;
  &lt;/bean&gt;
  </code></pre>