code: @SuppressWarnings("unchecked")
    public static <T> T instantiateGenerics(Class<?> type, String className) throws ClassInstantiationException {
      // TODO: can we do a verification that type conforms to T somehow?
      // (probably not because generics are implemented via erasure.
      try {
        try {
          return ((Class<T>) type).cast(CLASSLOADER.loadClass(className).newInstance());
        }
        catch(ClassNotFoundException e) {
          // try package of type
          return ((Class<T>) type).cast(CLASSLOADER.loadClass(type.getPackage().getName() + "." + className).newInstance());
        }
      }
      catch(InstantiationException | IllegalAccessException
          | ClassNotFoundException | ClassCastException e) {
        throw new ClassInstantiationException(e);
      }
    }
docs: Returns a new instance of the given type for the specified className.
  <p>
  If the class for className is not found, the instantiation is tried using
  the package of the given type as package of the given className.
  <p>
  This is a weaker type checked version of "{@link #instantiate}" for use
  with generics.
  
  @param <T> Class type for compile time type checking
  @param type desired Class type of the Object to retrieve
  @param className name of the class to instantiate
  @return a new instance of the given type for the specified className
  @throws ClassInstantiationException When a class cannot be instantiated.