When working in embeded mode, the JS engine does not look at the argument types when deciding which overloaded method to choose. Also using the nashorn notation to explicitly specify the overloaded method does not seem to be allowed.
A full reproducer is here:
https://gist.github.com/pmlopes/6021d34f920f8e24b391b38fcf1987e9
In this reproducer a Java object define an overloaded method which has the same arity but different argument types, the types are instantiated using:
Java.type('FQCN')
So at the engine level the type is known and not dynamic, when calling the method then this type seems to be ignored as due to the fact that the overloads have the same arity you'll see:
An exception occured while executing the Java class. TypeError:
INVOKE on JavaObject[bugs.Pool@39eb534c (bugs.Pool)] failed due to:
java.lang.IllegalArgumentException: Multiple applicable overloads found for method name prepare
(candidates: [
Method[public void bugs.Pool.prepare(java.lang.String,bugs.Tuple,bugs.Handler)],
Method[public void bugs.Pool.prepare(java.lang.String,java.util.stream.Collector,bugs.Handler)]
],
arguments: [
SELECT ... (String),
JavaObject[bugs.Tuple@8b41341 (bugs.Tuple)] (JavaObject),
DynamicObject<JSFunction>@daa14ca (DynamicObjectBasic)])
As you can see form the arguments the types are known and could lead to a proper match. The last argument is a functional interface, so the match should also be valid as js functions are "casted" to functional interfaces by default.
Thanks for the report. This seems to be a bug in method overload prioritization. The Tuple method is unambiguously the preferable one here.
The fix is merged now and will be in the release targeted for beginning of August.