Could you remove the casting here? Maybe change the getThriftClass to return Class<T> rather than Class<?>