public static <T, CTX> T createInstance(Class<T> targetClass, CTX optionalContext)
			throws IllegalArgumentException {

		try {
			if (optionalContext != null) {
				Constructor<T> ctor = getCtor(targetClass, optionalContext.getClass());
				if (ctor != null) {
					ctor.setAccessible(true);
					return ctor.newInstance(optionalContext);
				}
			}
			Constructor<T> ctor = getCtor(targetClass);
			if (ctor != null) {
				ctor.setAccessible(true);
				return ctor.newInstance();
			}
			throw new IllegalArgumentException("Missing ctor for " + targetClass.getSimpleName());
		}
		catch (SecurityException | InstantiationException | IllegalAccessException
				| InvocationTargetException e) {
			throw new IllegalArgumentException(e);
		}
	}
Creates an instance of the specified target class, using an optional context parameter
to the constructor.

@param <T> type of the class to be created
@param <CTX> type of the context to be passed to the constructor
@param targetClass class to be created
@param optionalContext anything, or null
@return new instance of type T
@throws IllegalArgumentException if error creating instance
Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/structmapping/ReflectionHelper.java