<div dir="ltr"><div dir="ltr">See MethodHandle::invokeWithArguments.</div><div dir="ltr"><br></div><div>Glavo</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 27, 2023 at 5:14 PM tison <<a href="mailto:wander4096@gmail.com">wander4096@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:arial,sans-serif">I'm using OpenJDK 21 and prototyping FFM APIs.</div><div class="gmail_default" style="font-family:arial,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,sans-serif">Instead of passing the MethodHandle returned by linker.downcallHandle here and there, I'm trying to wrap it into a NativeMethod class:</div><div class="gmail_default" style="font-family:arial,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,sans-serif">public final class NativeMethod {<br> private final String name;<br> private final FunctionDescriptor descriptor;<br> private final MethodHandle handle;<br></div><div class="gmail_default" style="font-family:arial,sans-serif"> public Object invoke(Object... args) throws Throwable {<br> return this.handle.invoke(args);<br> }<br>}<br></div><div class="gmail_default" style="font-family:arial,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,sans-serif">But it seems the varargs pass through is not quit fluent:</div><div class="gmail_default" style="font-family:arial,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,sans-serif">java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(int)int to (Object[])Object<br><br> at java.base/java.lang.invoke.MethodHandle.asTypeUncached(MethodHandle.java:903)<br> at java.base/java.lang.invoke.MethodHandle.asType(MethodHandle.java:870)<br> at java.base/java.lang.invoke.Invokers.checkGenericType(Invokers.java:541)<br> at io.montumi.datafusion.core.NativeMethod.invoke(NativeMethod.java:22)<br></div><div class="gmail_default" style="font-family:arial,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,sans-serif">While if I public the handle and call invoke from the handle directly, all the behavior is expected.</div><div class="gmail_default" style="font-family:arial,sans-serif"><br></div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><font face="arial, sans-serif">Best,</font></div><div><font face="arial, sans-serif">tison.</font></div></div></div></div></div></div></div></div></div></div></div>
</blockquote></div>