title: mozilla rhino overriding an object method from javascript
body: <p>I'm looking for overriding a java method from javascript in rhino. Here is my code:</p>
  
  <pre><code>public class CustomClass {
  public String s="some string";
  public void doSomething(){}
  }
  </code></pre>
  
  <p>and then:</p>
  
  <pre><code>        Object wrappedOut = Context.javaToJS(new CustomClass(), scope);
          ScriptableObject.putProperty(scope, "CustomClass", wrappedOut);
          String s="CustomClass.s='aaa'; \n CustomClass.doSomething=function(args){};";
          Object result = cx.evaluateString(scope, s, "&lt;cmd&gt;", 1, null);
  </code></pre>
  
  <p>So it is possible to change the value to CustomClass.s but not to the method doSomething</p>
  
  <p>I receive the following error:</p>
  
  <blockquote>
    <p>org.mozilla.javascript.EvaluatorException: Java method "doSomething"
    cannot be assigned to. (#2)</p>
  </blockquote>
  
  <p><strong>UPDATE</strong>
  As requested in the comments here is my complete source code:</p>
  
  <p>CustomClass.java</p>
  
  <pre><code>public class CustomClass {
      public String s="Do something now!";
  
      public void doSomething(Object ... v){
          System.out.println("do something");
      }
  }
  </code></pre>
  
  <p>Scripting.java</p>
  
  <pre><code>import org.mozilla.javascript.*;
  public class Scripting {
      public static void main(String args[])
      {
  
          Context cx = Context.enter();
          try {
  
              Scriptable scope = cx.initStandardObjects();
  
              Object wrappedOut = Context.javaToJS(new CustomClass(), scope);
              ScriptableObject.putProperty(scope, "CustomClass", wrappedOut);
  
  
              String s="CustomClass.doSomething=function(args){};";
  
              Object result = cx.evaluateString(scope, s, "&lt;cmd&gt;", 1, null);
  
              System.err.println(Context.toString(result));
          }catch(WrappedException e){
              e.printStackTrace();
  
          } catch(Exception e){
              e.printStackTrace();
          }finally {
              // Exit from the context.
              Context.exit();
          }
      }
  }
  </code></pre>