@SuppressWarnings({ "unchecked", "TypeParameterUnusedInFormals" })
  // Used server-side too by Aggregation Coprocesor Endpoint. Undo this interdependence. TODO.
  public static <T extends Message> T getParsedGenericInstance(Class<?> runtimeClass, int position,
    ByteString b) throws IOException {
    Type type = runtimeClass.getGenericSuperclass();
    Type argType = ((ParameterizedType) type).getActualTypeArguments()[position];
    Class<T> classType = (Class<T>) argType;
    T inst;
    try {
      Method m = classType.getMethod("parseFrom", ByteString.class);
      inst = (T) m.invoke(null, b);
      return inst;
    } catch (SecurityException e) {
      throw new IOException(e);
    } catch (NoSuchMethodException e) {
      throw new IOException(e);
    } catch (IllegalArgumentException e) {
      throw new IOException(e);
    } catch (InvocationTargetException e) {
      throw new IOException(e);
    } catch (IllegalAccessException e) {
      throw new IOException(e);
    }
  }
Get an instance of the argument type declared in a class's signature. The argument type is
assumed to be a PB Message subclass, and the instance is created using parseFrom method on the
passed ByteString.
@param runtimeClass the runtime type of the class
@param position     the position of the argument in the class declaration
@param b            the ByteString which should be parsed to get the instance created
@return the instance
@throws IOException Either we couldn't instantiate the method object, or "parseFrom" failed.
hbase-endpoint/src/main/java/org/apache/hadoop/hbase/client/coprocessor/AggregationHelper.java