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开发者_StackOverflow社区 that is a very ugly hack that I don't want to do.
Thanks.
You need a helper method:
private <T> List<T> createList(Class<T> klass) {
return new ArrayList<T>();
}
精彩评论