private static Type resolveTypeVariableWithBound(Type type) {
    if (type instanceof TypeVariable) {
      List<Class<?>> upperBounds = GenericTypeReflector.getUpperBoundClassAndInterfaces(type);
      if (upperBounds.size() == 1) {
        return upperBounds.get(0);
      } else {
        return Object.class;
      }
    }
    if (type instanceof ParameterizedType) {
      ParameterizedType paramType = (ParameterizedType) type;
      for (Type actualTypeArgument : paramType.getActualTypeArguments()) {
        if (actualTypeArgument instanceof TypeVariable) {
          //We still have TypeVariable in the parameter type, we can't construct a new ParameterizedType easily here, so erase the type
          return GenericTypeReflector.erase(type);
        }
      }
    }
    return type;
  }
Resolves the return type of the given method in the given type, with the method {@link GenericTypeReflector#getReturnType(Method, Type)}.

<p>In difference to the method of the library, this method will resolve unknown {@link java.lang.reflect.TypeVariable}s to the upper bound of the type variable.

@param method        the method for which the return type shall be resolved
@param declaringType the declaring type of the {@code method}
@return the resolved type
spock-core/src/main/java/org/spockframework/util/GenericTypeReflectorUtil.java