title: Using .apply() on a Java method from rhino (JavaScript)
body: <p>I want to use rhino's (JavaScript's) <code>function.apply()</code> to pass arguments to a varags Java method, something like this:</p>
  
  <pre><code>function sprintf()
  {
      return java.lang.String.format.apply(arguments);
  }
  sprintf("%d\n", 5);
  </code></pre>
  
  <p>But invoking <code>sprintf()</code> gives an error:</p>
  
  <pre><code>Error: can't find method java.lang.String.format().
  </code></pre>
  
  <p>I suppose this is because the <code>format()</code> method isn't a proper JavaScript function but a Java method, so it doesn't have <code>apply()</code> defined.  (Although that's not what the error message seems to say, so maybe not.)</p>
  
  <p>I do find that I can add my own apply() method:</p>
  
  <pre><code>java.lang.String.format.apply = function() {}
  </code></pre>
  
  <p>But I can't see how to write <code>apply()</code> without <code>apply()</code>, if you see what I mean.  Any ideas?</p>