How can I override or implement a method from a java class in my script?

0 votes
asked Nov 30, 2017 by ben-s-7515 (12,640 points)
I have a script using a java library and I need to implement or override a method in that object.  How is this done in QIE when running the javascript under RHINO?

1 Answer

0 votes

If I have a simple java class like this:

public class MyClass() {
   public String myMethod() {
      return "MyValue";
   public String myMethodWithParameter(final String parameter) {
      return "MyValue" + parameter;

I could override the "myMethod()" class using this script:

var myClass = new MyClass() {
   myMethod: function() { return "MyNewValue"; }
   myMethodWithParameter: function(parameter) { return "MyNewValue" + parameter; }

In this example both the "myMethod" and the "myMethodWithParameter" are implemented now in the script instead of the java class.

answered Nov 30, 2017 by ben-s-7515 (12,640 points)