title: Use ScriptEngine to bind global javascript functions from java code
body: <pre><code>public class JSBindings extends SimpleBindings{
  
      public void bind(String key, Object value){
          this.put(key, value);
      }
  }
  </code></pre>
  
  <p>I pass the instance of JSBindings to <code>ScriptEngine.eval(script, bindings)</code> in my code. However, I am only able to bind (put) java objects to SimpleBindings. How can I bind global javascript functions from java code?</p>
  
  <p>i.e</p>
  
  <pre><code>bind("UTILS", new SomeJavaObject()) //works fine..
  </code></pre>
  
  <p>But I want to bind javascript functions. Perhaps something like this :</p>
  
  <p><code>bind("list", "function(){return new java.util.ArrayList()}")</code> <code>//doesn't work.. list is just a string</code></p>
  
  <p>so that when I say <code>list()</code> in my javascript, it must invoke this bind function and create an instance of ArrayList. Is it possible to bind javascript functions this way from an instance of SimpleBindings?</p>