Suppose I have the following hierarchy of classes:

```
public class MainClass {

}

class A extends MainClass {

}

class B extends MainClass {

}

class C extends MainClass {

}

```

Now suppose I have a `List<MainClass> classes` which looks like:

```
 {A, MainClass, A, B, B, MainClass, C, A, C, B, A}

```

I want to be able to pick out sublists of objects by their class. For example, I would like to be able to extract only those classes in this list of class A (but not class MainClass). As such, using isAssignableFrom(A.class) will not work for me. 

My current method looks like:

```
public <T extends MainClass> List<T> getClasses(List<MainClass> classes, Class classToCollect) {
    List<T> subclasses = new ArrayList<T>();

    for (MainClass clazz : classes) {
        if (clazz.getClass().isInstance(classToCollect)) {
            subclasses.add((T)clazz);
        }
    }

    return subclasses;
}

```

This still doesn't work and passes back an empty list. What gives here?