title: CDI Ambiguous dependency with @Produces - why?
body: <p>I am using code like below:</p>
  
  <pre><code>public Configuration {
  
      private boolean isBatmanCar = someMethod(...);
  
      @Produces
      public Car getCar(@New Car car) {
          if(isBatmanCar) {
              car.setName("BatmanCar");
          }
          return car;
      }
  }
  
  public Car {
      private String name = "NormalCar";
  
      public void setName(String name) {
          this.name = name;
      }
  }
  
  public Demo {
      @Inject
      Car car;
  
      // rest of code
  }
  </code></pre>
  
  <p>When I deploy an application to glassfish (Java EE 6 btw) I get </p>
  
  <p><code>AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between (...) Car with qualifiers [@Any @Default] (...) Producer Method [Car] with qualifiers [@Any @Default]</code></p>
  
  <p>I know that when I add <code>@Alternative</code> to Car class it will work, but I wonder if this is the proper way to do it, and why do I have to do it?</p>
  
  <p>Can you tell me what is the correct usage of @Produces in such case?</p>
  
  <p>I'm using Java EE 6, CDI 1.0, EJB 3.1, Glassfish 3.2</p>