Q: How do you get an instance of java.lang.Class for a generic collection like Collection? How do you get an instance of java.lang.Class for a generic collection like Collection<SomeObject>?
I'm looking for something like the following:
Class clazz = Collection<SomeObject>.class;


A: You can't. Type erasure means that you can't do this this way.
What you can do is:


*

*declare a field of the generic type.

*call the reflection API to get a Type. E.g. Field.getGenericType().

*Use the Type API to see the parameter.


A: As others said, the types are erased at runtime. You must provide the class object to your method. Assuming all your classes that extend SomeObject have constructors with no parameters, you can create objects using reflection. Example:  
public <T extends SomeObject> Collection<T> getObjects(Class<T> clazz) {
    List<T> result = new ArrayList<T>();
    for(int i=0; i<3; i++) {
        try {
            T t = clazz.getConstructor((Class[]) null).newInstance((Object[]) null);
            // do something with t
            result.add(t);
        } catch (Exception e) {
            // handle exception
        }
    }
    return result;
}

If you have a class that extends SomeObject, you can use the method like this:
class ObjA extends SomeObject {
}

Collection<ObjA> collection = getObjects(ObjA.class);


A: At runtime these types are erased. If you take an instance of Collection and call getClass(), you will simply get the Collection class. 
There are other reflection APIs to get information about members declared with a type parameter. 
