<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>You could do something like this:</div><div><br></div><div><div>&nbsp; &nbsp; @SuppressWarnings({"unchecked"})</div><div>&nbsp; &nbsp; @Produces</div><div>&nbsp; &nbsp; public GenericQuery injectClass(InjectionPoint ip) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Annotated annotated = ip.getAnnotated();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Class clazz = Object.class;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Type type = annotated.getBaseType();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; if (type instanceof ParameterizedType) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ParameterizedType pt = (ParameterizedType) type;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clazz = (Class) pt.getActualTypeArguments()[0];</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return new GenericQuery(clazz);</div><div>&nbsp; &nbsp; }</div><div><br></div><div>--</div><div><br></div><div><div>&nbsp; &nbsp; @Inject</div><div>&nbsp; &nbsp; GenericQuery&lt;String&gt; gqs;</div><div>&nbsp; &nbsp; @Inject</div><div>&nbsp; &nbsp; GenericQuery&lt;Number&gt; gqn;</div></div><div><br></div><div>--</div><div><br></div><div><div><div>&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("GQS: " + gqs.getClazz());</div><div>&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("GQN: " + gqn.getClazz());</div></div></div><div><br></div><div>--</div><div><br></div><div><div>GQS: class java.lang.String</div><div>GQN: class java.lang.Number</div></div><div><br></div><div>--</div><div><br></div><div><a href="https://github.com/alesj/cdi-arq-workshop/commit/64860f15197be40a7714dfd8a7da931c1db11411">https://github.com/alesj/cdi-arq-workshop/commit/64860f15197be40a7714dfd8a7da931c1db11411</a></div><div><br></div><div>HTH</div><div><br></div><div>-Ales</div></div><div><br class="Apple-interchange-newline"><blockquote type="cite">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>
_______________________________________________<br>seam-dev mailing list<br><a href="mailto:seam-dev@lists.jboss.org">seam-dev@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/seam-dev<br></blockquote></div><br></body></html>