You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to explicitly select a Java method overload? #37
When calling a Java method from JS, if multiple overloads are applicable, the runtime correctly complains that it can't choose (please forgive the nonsensical example):
$ js --jvm
> Graal
{language: "JavaScript", versionJS: "1.0", versionGraalVM: "1.0.0-rc5", isGraalRuntime: true}
> java.lang.Runtime.getRuntime().exec(null)
TypeError: INVOKE on JavaObject[java.lang.Runtime@799f10e1 (java.lang.Runtime)] failed due to: java.lang.IllegalArgumentException: Multiple applicable overloads found for method name exec (candidates: [Method[public java.lang.Process java.lang.Runtime.exec(java.lang.String[]) throws java.io.IOException], Method[public java.lang.Process java.lang.Runtime.exec(java.lang.String) throws java.io.IOException]], arguments: [DynamicObject<null>@18078bef (DynamicObjectBasic)])
at <js> :program(<shell>:3:1:0-35)
This is in line with Nashorn:
$ jjs -version
nashorn 1.8.0_121
jjs> java.lang.Runtime.getRuntime().exec(null)
java.lang.RuntimeException: java.lang.NoSuchMethodException: Can't unambiguously select between fixed arity signatures [(java.lang.String), (java.lang.String[])] of the method java.lang.Runtime.exec for argument types [null]
However Nashorn lets us pick an overload to resolve the ambiguity:
> java.lang.Runtime.getRuntime()["exec(java.lang.String)"](null)
TypeError: (intermediate value).lang.Runtime.getRuntime(...)["exec(java.lang.String)"] is not a function
at <js> :program(<shell>:8:1:56-61)
Activity
Experimental explicit overload resolver
woess commentedon Dec 7, 2020
java.lang.Runtime.getRuntime()["exec(java.lang.String)"]is supported since 21.0.0.