Apparently generics do not allow you to cast using the generic type T. Changed cast using the Class<T> type.