I’m working with the JPA API (Hibernate-backed), and have the following code:
public List<?> getGenericListing(Class<?> clazz) {
//Other logic comes before...
Query qry = entityManager.createNativeQuery(sql, clazz);
return qry.getResultList(); //Returns an untyped list, part of JPA spec
}
public List<SpecificObject> getSpecificListing() {
return (List<SpecificObject>) getGenericListing(SpecificObject.class);
}
Is there a better way to return the List<?> other than type-casting it against the List of SpecificObject?
You can put the cast into
getGenericListing: