title: Javascript .apply() method equivalent in Java?
body: <p>I want to create a class in Java from a classname and an variable number of arguments (i.e. an Object[] args with variable length). Is there any way to achieve that?</p>
  
  <p>Basically, the method would look like this in Javascript</p>
  
  <pre><code>function createClass(classname, args) {
      protoObject = Object.create(window[classname].prototype);
      return window[classname].apply(protoObject,args) || protoObject;
  }
  // I want to be able to do this:
  var resultClass = createClass("someClass", someArrayOfArgs);
  </code></pre>
  
  <p>A simpler function to only call a function would look like </p>
  
  <pre><code>function callFunction(functionName, args) {
      return window[functionName].apply(null,args);
  }
  </code></pre>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p>For clarification, this would be some example usage in Javascript:</p>
  
  <pre><code>function multiplyResult(var1,var2) { 
      return var1*var2;
  }
  var result = callFunction("multiplyResult", ["5", "2"]); // == 10
  
  function multiplyObject(var1,var2) { 
      var result = var1 * var2;
      this.getResult = function() { return result }; 
  }
  var result = createClass("multiplyObject", ["5", "2"]).getResult(); // == 10
  </code></pre>