<div dir="ltr">BTW, if I take the @Alternative producer out (so there is no more @Alternative) but leave the &lt;alternative&gt; element, the Weld error message is :<div><br></div><div><font face="courier new, monospace">WELD-001422: Enabled alternative &lt;class&gt;org.agoncal.cdi.PrefixProducer&lt;/class&gt; in file:/beans.xml@7 is not an alternative<br></font></div><div><br></div><div>Again, the error message is very &quot;bean&quot; oriented, don&#39;t you think ?</div><div><br></div><div>Antonio</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 21, 2014 at 4:10 PM, Antonio Goncalves <span dir="ltr">&lt;<a href="mailto:antonio.goncalves@gmail.com" target="_blank">antonio.goncalves@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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><font face="courier new, monospace"><span><b>public class </b></span><span>PrefixProducer<br>
{</span><i><br>
   </i><span>@Produces<br>
   </span><span><b>public </b></span><span>String </span><span><b>prefixNonAlt </b></span><span>= </span><span><b>&quot;non-alternative&quot;</b></span><span>;<br>
<br>
   </span><span>@Produces<br>
<font color="#ff0000"><b>   @Alternative</b><br></font>
   </span><span><b>public </b></span><span>String </span><span><b>prefixAlt </b></span><span>= </span><span><b>&quot;alternative&quot;</b></span></font><span><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><font face="courier new, monospace">&lt;<span><b>alternatives</b></span>&gt;<span><br>
  </span>&lt;<span><b>class</b></span>&gt;<span>org.agoncal.cdi.</span>PrefixProducer&lt;/<span><b>class</b></span>&gt;<span><br>
</span>&lt;/<span><b>alternatives</b></span>&gt;<span><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><span class="HOEnZb"><font color="#888888"><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></font></span></div>
<br>_______________________________________________<br>
cdi-dev mailing list<br>
<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Antonio Goncalves <br>Software architect, Java Champion and Pluralsight author<br><br><a href="http://www.antoniogoncalves.org" target="_blank">Web site</a> | <a href="http://twitter.com/agoncal" target="_blank">Twitter</a> | <a href="http://www.linkedin.com/in/agoncal" target="_blank">LinkedIn</a> | <a href="http://pluralsight.com/training/Authors/Details/antonio-goncalves" target="_blank">Pluralsight</a> | <a href="http://www.parisjug.org" target="_blank">Paris JUG</a> | <a href="http://www.devoxx.fr" target="_blank">Devoxx France</a></div>
</div>