tags:

views:

82

answers:

1

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.

+3  A: 

You need a helper method:

 private <T> List<T> createList(Class<T> klass) {
          return new ArrayList<T>();
 }
Yishai