public static Type getGenericClassType(Object instance, Class<?> clazz, int position) {
    Class<?> type = instance.getClass();
    while (type != Object.class) {
      if (type.getGenericSuperclass() instanceof ParameterizedType) {
        ParameterizedType genericSuperclass = (ParameterizedType) type.getGenericSuperclass();
        if (genericSuperclass.getRawType() == clazz) {
          return genericSuperclass.getActualTypeArguments()[position];
        } else {
          type = type.getSuperclass();
        }
      } else {
        type = type.getSuperclass();
      }
    }
    return null;
  }
public static Type getGenericClassType ( Object instance , Class < ? > clazz , int position ) { Class < ? > type = instance . getClass ( ) ; while ( type != Object . class ) { if ( type . getGenericSuperclass ( ) instanceof ParameterizedType ) { ParameterizedType genericSuperclass = ( ParameterizedType ) type . getGenericSuperclass ( ) ; if ( genericSuperclass . getRawType ( ) == clazz ) { return genericSuperclass . getActualTypeArguments ( ) [ position ] ; } else { type = type . getSuperclass ( ) ; } } else { type = type . getSuperclass ( ) ; } } return null ; }
Returns the generic type at the given position for the given class.

@param instance the implementing instance
@param clazz    the generic class
@param position the generic position
@return the generic type at the given position