Object classLoader = createClassLoaderHandle.invokeWithArguments(new Object[] { contextObject, null });
return classLoader;
}
private static Object createContextObject(Class contextClass, MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException, Throwable {
MethodType findConstructorType = MethodType.methodType(MethodHandle.class, Class.class, new Class[] { MethodType.class });
MethodHandle findConstructorHandle = lookup.findVirtual(MethodHandles.Lookup.class, "findConstructor", findConstructorType);
MethodType constructorType = MethodType.methodType(Void.TYPE);
MethodHandle constructorHandle = (MethodHandle) findConstructorHandle.invokeWithArguments(new Object[] { lookup, contextClass, constructorType });
Object contextObject = constructorHandle.invokeWithArguments(new Object[0]);
return contextObject;
}