Possible Duplicates:
Get generic type of class at runtime
How to get the generic type at runtime?
Hi there,
How I can get the type for a generic type in java at runtime?
In C# I can use the typeof
operator. With the typeof
operator I get a type object with further information about the type of this generic type at runtime.
Is there a equivalent operator in Java?
Thanks in advance.
Kind regards, patrick
//Edit :
What I want to do :
public ArrayList<T> SelectObjects() {
// I need to get here the type name for the oql script!
//this.SelectObjects( "select p from " + Class.forName(T));
}
public ArrayList<T> SelectObjects(String oql) {
try {
Iterator<T> iterator =
this.em.createQuery(oql).getResultList().iterator();
ArrayList<T> objects =
new ArrayList<T>();
while(iterator.hasNext())
{
objects.add(iterator.next());
}
return objects;
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
I set up an oql script dynamically. How can I get the type from T?
Thanks!