<div dir="ltr">Hi all,<div><br></div><div>I often use code such as the one below: one bean, two producers and one producer is an alternative (not the bean) :</div><div><br></div><div>







<p class=""><font face="courier new, monospace"><span class=""><b>public class </b></span><span class="">PrefixProducer<br>
{</span><i><br>
   </i><span class="">@Produces<br>
   </span><span class=""><b>public </b></span><span class="">String </span><span class=""><b>prefixNonAlt </b></span><span class="">= </span><span class=""><b>&quot;non-alternative&quot;</b></span><span class="">;<br>
<br>
   </span><span class="">@Produces<br>
<font color="#ff0000"><b>   @Alternative</b><br></font>
   </span><span class=""><b>public </b></span><span class="">String </span><span class=""><b>prefixAlt </b></span><span class="">= </span><span class=""><b>&quot;alternative&quot;</b></span></font><span class=""><font face="courier new, monospace">;<br>
}</font><br>
</span></p></div><div><br></div><div>I enable the alternative, as usual, by declaring the bean in the beans.xml :</div><div><br></div><div>







<p class=""><font face="courier new, monospace">&lt;<span class=""><b>alternatives</b></span>&gt;<span class=""><br>
  </span>&lt;<span class=""><b>class</b></span>&gt;<span class="">org.agoncal.cdi.</span>PrefixProducer&lt;/<span class=""><b>class</b></span>&gt;<span class=""><br>
</span>&lt;/<span class=""><b>alternatives</b></span>&gt;<span class=""><br>
</span></font></p></div><div><br></div><div>This works fine, no problem. But I just realized that Intellij IDEA displays the warning &quot;Alternative class expected here&quot;. I&#39;ve looked around, read the spec, the Weld documentation, and didn&#39;t find any example of the code above. I think people are unware of this. The only reference of alternative producers I found is in the spec : </div><div><br></div><div><div><i>5.1.1.2</i></div><div><i>An alternative is selected for the bean archive if either:</i></div><div><i>* the alternative is a producer method, field or resource, and the bean class that declares the method or field is listed<br></i></div><div><br></div></div><div>I think for such easy use cases (i.e PrefixProducer) there is no need to multiply beans, so the code is fine and easy to read. But the code you see around, tend to multiply beans (people think that Alternatives are *only* for beans, not for producers).</div><div><br></div><div>Shouldn&#39;t the spec/Weld documentation mention this case a bit more often, by giving an example ? </div><div><br></div><div>WDYT ? </div><div><br></div><div>Antonio</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div> </div></div>