Reputation: 881
I am mocking an interface that doesn't use generics, but does take a Class
type as an argument.
public Object query(Class c, Filter f)
{....}
Is there a way in my implementation to use c
as the argument for a generic?
eg.
return new ArrayList<c>();
Obviously I could do a switch
if I had a know set of values for c
, but that is a very ugly hack that I don't want to do.
Thanks.
Upvotes: 5
Views: 1208
Reputation: 91871
You need a helper method:
private <T> List<T> createList(Class<T> klass) {
return new ArrayList<T>();
}
Upvotes: 5