<html><body><div style="color:#000; background-color:#fff; font-family:tahoma, new york, times, serif;font-size:10pt"><div style="font-family: tahoma, 'new york', times, serif; "><span>Hi all..</span></div><div style="font-family: tahoma, 'new york', times, serif; "><span><br></span></div><div style="font-family: tahoma, 'new york', times, serif; "><span>I'm not sure whether my comment is help you or not, but I ever thinking about this some time ago, and may be could be archived by something like:</span></div><div style="font-family: tahoma, 'new york', times, serif; "><span><br></span></div><div><span><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">public class Foo&lt;T&gt; {</font></span></div><div><span><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">&nbsp; private Class&lt;T&gt; clazz;</font></span></div><div><span><font class="Apple-style-span" face="'Courier
 New', courier, monaco, monospace, sans-serif">&nbsp;&nbsp;</font></span></div><div><span><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">&nbsp;&nbsp;</font></span><span class="Apple-style-span" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; ">@Inject</span></div><div><span><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">&nbsp; public Foo(Class&lt;T&gt; c) {</font></span></div><div><span><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">&nbsp; &nbsp; this.clazz = c;</font></span></div><div><span><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">&nbsp; }</font></span></div><div><span><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">}</font></span></div><div style="font-family: tahoma, 'new york', times, serif;
 "><span><br></span></div><div style="font-family: tahoma, 'new york', times, serif; ">And by using custom qualifier, creating instance of Foo is just like:</div><div><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">@InjectConstructor(Blah.class)<br></font></div><div><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">private Foo&lt;Blah&gt; foo;</font></div><div style="font-family: tahoma, 'new york', times, serif; "><br></div><div style="font-family: tahoma, 'new york', times, serif; ">Am I missing something?</div><div style="font-family: tahoma, 'new york', times, serif; "><br></div><div style="font-family: tahoma, 'new york', times, serif; "><br></div><div style="font-family: tahoma, 'new york', times, serif; ">Thanks,</div><div style="font-family: tahoma, 'new york', times, serif; ">xsalefter</div><div style="font-family: tahoma, 'new york', times, serif;
 "><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px;">  <div style="font-size: 10pt; font-family: tahoma, 'new york', times, serif; "> <div style="font-size: 12pt; font-family: 'times new roman', 'new york', times, serif; "> <font size="2" face="Arial"> </font><br><div id="yiv1610057272">Hey guys, how you doing?<div><br></div><div><div>I'm trying to achieve something that might be impossible, but before concluding that, I'd like to ask you, CDI gurus!</div><div><br></div><div>I have the following class:</div>
<div><br></div><div>public class Foo&lt;T&gt; {</div><div><br></div><div>&nbsp; &nbsp; public TypedQuery&lt;T&gt; getQuery(){</div><div><br></div><div>&nbsp; &nbsp; }</div><div><br></div><div>}</div><div><br></div><div>As you can Imagine, inside my getQuery method, I'd have to use "T.class" to make it TypedQuery. which is impossible due java generics type erasure.</div>
<div><br></div><div>so I'd have to build a private field to hold the t.class for me.</div><div><br></div><div><div>public class Foo&lt;T&gt; {</div><div><br></div><div>&nbsp; &nbsp; private Class&lt;T&gt; klass;</div><div><br></div>
<div>&nbsp; &nbsp; public TypedQuery&lt;T&gt; getQuery(){</div><div><br></div><div>&nbsp; &nbsp; }</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; public void setKlass(Class&lt;T&gt; klass){</div><div>&nbsp; &nbsp; &nbsp; &nbsp; this.klass = klass;</div><div>&nbsp; &nbsp; }</div><div>}</div>
</div><div><br></div><div>The problem is that forcing this 'setKlass' feels very ugly to the api, and it's not very error prone, since one could easily forget to set this configuration.</div><div><br></div><div>
So I had an Idea: force the setKlass inside the constructor:</div><div><br></div><div><div>public class Foo&lt;T&gt; {</div><div><br></div><div>&nbsp; &nbsp; private Class&lt;T&gt; klass;</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; public Foo(Class&lt;T&gt; klass){</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;this.klass = klass;</div><div>&nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; public TypedQuery&lt;T&gt; getQuery(){</div><div><br></div><div>&nbsp; &nbsp; }</div><div><br></div><div>}</div></div><div><br></div><div>Unfortunatelly, this breaks cdi, since it cannot inject it anymore. At least&nbsp;AFAIK.</div>
<div><br></div><div>So, is there a way out of this? maybe using a secret solder feature?</div></div>
</div><br> </div> </div> </blockquote></div>   </div></body></html>