Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Class get generic type at runtime CDI Date: Fri, 19 Dec 2014 15:29:59 +0100 Lines: 37 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net hRGwiyUCZ6y3JAlVMRykVQBIlND9fAeR3GSz2HSYZ1pNyKUI4= Cancel-Lock: sha1:Ij+4tIIeZQMjQl1Q4N/lDHDUBuA= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:30595 On 19.12.2014 13:23, Leonan Luppi wrote: > Hello, > > I'm try to get generic class type but isn't work. Someone can help > me? I'm using CDI Weld to Inject my DAO class with a generic type: > > > @Inject > private DAO dao; > > And my DAO Class: > > public class DAO { > > public T findAll() { > CriteriaQuery query = em.getCriteriaBuilder() > .createQuery(HERE_MY_GENERIC_CLASS); > query.select(query.from(HERE_MY_GENERIC_CLASS)); > return (T) em.createQuery(query).getResultList(); > } > > } > > > How can i get at runtime? To make a query. Judging from the code you presented you need at least to return a collection of T (e.g. Iterable) and not a T. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/