Instead of accepting the String
type, accept a Class
parameter with a generic type parameter.
public <P extends Product> List<P> queryProducts (Class<P> clazz) {
List<P> response = new ArrayList<P>();
...
return response;
}
The caller can execute
Product p = Product.getProductByType(type);
to get the object, and then call getClass()
to pass in the Class
necessary.