code: public static Class<?> getDeclaredGenericType(Class<?> clazz, Class<?> genericInterface) {
          Type[] genericInterfaces = clazz.getGenericInterfaces();
          for (Type genericType : genericInterfaces) {
              if (genericType instanceof ParameterizedType) {
                  ParameterizedType paramType = (ParameterizedType) genericType;
                  if (paramType.getRawType().equals(genericInterface)) {
                      Type type = paramType.getActualTypeArguments()[0];
                      return getActualRawType(type);
                  }
              }
          }
          return null;
      }
docs: Finds the generic type declared on a single interface implemented by the provided class.
  If the generic type is itself a generic type (ex: <pre>{@code SomeType<SomeOtherType<T>>}</pre>,
  the actual raw type will be returned (in the previous example, `SomeOtherType` would be returned).
  
  @param clazz            the class on which we want to find the generic type.
  @param genericInterface the interface we're looking for.
  @return the actual type declared on the provided generic interface.