-
Bug
-
Resolution: Fixed
-
P3
-
6
-
b91
-
generic
-
generic
The javax.script.Invocable interface contains the following methods:
invoke(Object this, String name, Object...args)
invoke(String name, Object...args)
The first is used to invoke methods of the script object "this", the second is used to invoke functions defined in a script. The problem arises when invoking a function all of whose arguments are Strings.
In this case, the call
Object ret = engine.invoke("functionName", "arg1", "arg2", "arg3");
is ambiguous. javac can't tell which invoke overload is being called. User gets an error that looks like:
reference to invoke is ambiguous, both method invoke(java.lang.Object, java.lang.String,java.lang.Object...) in javax.script.Invocable and method invoke(java.lang.String,java.lang.Object...) in javax.script.Invocable match
It is easy to work around this by doing something like:
Object ret = engine.lnvoke("functionName", new Object[]{"arg1", "arg2", "arg3"});
but most users will be very confused by the javac error. We need to fix this.
If we rename the invoke methods as "invokeMethod" and "invokeFunction" so that both the
"invoke" variants can still remain varargs and we can avoid javac error.
invoke(Object this, String name, Object...args)
invoke(String name, Object...args)
The first is used to invoke methods of the script object "this", the second is used to invoke functions defined in a script. The problem arises when invoking a function all of whose arguments are Strings.
In this case, the call
Object ret = engine.invoke("functionName", "arg1", "arg2", "arg3");
is ambiguous. javac can't tell which invoke overload is being called. User gets an error that looks like:
reference to invoke is ambiguous, both method invoke(java.lang.Object, java.lang.String,java.lang.Object...) in javax.script.Invocable and method invoke(java.lang.String,java.lang.Object...) in javax.script.Invocable match
It is easy to work around this by doing something like:
Object ret = engine.lnvoke("functionName", new Object[]{"arg1", "arg2", "arg3"});
but most users will be very confused by the javac error. We need to fix this.
If we rename the invoke methods as "invokeMethod" and "invokeFunction" so that both the
"invoke" variants can still remain varargs and we can avoid javac error.