Sundararajan's Weblog

  • Java
    July 14, 2006

Recent changes in JSR-223

Guest Author

As you may know already, Mustang (Java SE 6) includes JSR-223: Scripting for the Java Platform API. There was a recent change (since Mustang build 91) in javax.script.Invocable interface. Previously, there were two invoke methods in this interface - one for calling script top-level or global functions from Java and another for calling methods on script object. These have been renamed to invokeFunction and invokeMethod respectively.

javax.script.Invocable interface used to have the following methods:

// call script global function
invoke(String name, Object...args)
// call method on a script object
invoke(Object this, String name, Object...args)

This results in a problem when invoking a function with String arguments. For example, the following call

Object ret = engine.invoke("functionName", "arg1", "arg2", "arg3");

is ambiguous. javac cannot 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

Now, these methods have been renamed to

// call a script global function
invokeFunction(String name, Object...args)
// call a method on a script object
invokeMethod(Object this, String name, Object...args)

The JavaScript engine (co-bundled in Sun's Java SE 6 implementation) and the script engines maintained at http://scripting.dev.java.net have been fixed to track this interface change. If you are maintaining/implementing your own JSR-223 engine, please fix it for this change.

In addition to this, scripting.dev.java.net project has been updated to use
  1. Groovy version 1.6 JSR-06
  2. JRuby version 0.9.0
  3. to track recent changes with JSR-199 (Java compiler API) [for Java script engine]

If you are using http://phobos.dev.java.net, you may want to refer to Roberto Chinnici's blog entry titled Tracking JSR-223 Changes

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.