-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
repo-babylon
From Tagir:
https://mail.openjdk.org/pipermail/babylon-dev/2024-July/001096.html
"
1. NewOp does not provide a direct way to resolve a constructor. For InvokeOp, one can use op.invokeDescriptor().resolveToHandle(lookup), but creating an instance having a NewOp in hands is more tricky. I do it like this
Class<?>[] argTypes = newOp.constructorType().parameterTypes().stream()
.map(this::toClass).toArray(Class[]::new);
Class<?> objType = toClass(newOp.type());
Object result = objType.getConstructor(argTypes).newInstance(arguments.toArray());
(where toClass is a helper method to get a class from the type). I feel that there should be a simple method to resolve to a Constructor or a MethodHandle.
"
https://mail.openjdk.org/pipermail/babylon-dev/2024-July/001096.html
"
1. NewOp does not provide a direct way to resolve a constructor. For InvokeOp, one can use op.invokeDescriptor().resolveToHandle(lookup), but creating an instance having a NewOp in hands is more tricky. I do it like this
Class<?>[] argTypes = newOp.constructorType().parameterTypes().stream()
.map(this::toClass).toArray(Class[]::new);
Class<?> objType = toClass(newOp.type());
Object result = objType.getConstructor(argTypes).newInstance(arguments.toArray());
(where toClass is a helper method to get a class from the type). I feel that there should be a simple method to resolve to a Constructor or a MethodHandle.
"