lundi 19 octobre 2015

Variable args reflection method invoke

The user will type the method to be called and the arguments of it. i.e.:

  • function1 param1
  • function2 param1 param2
  • functionN param1 param2 .. paramN

Assuming all parameters are strings, I save all the input of the user in a stack of strings:

LinkedList<String> stack = new LinkedList<String>();

And then, using reflection I obtain the method:

SpreadSheet myClass = new SpreadSheet();
Class objClass = myClass.getClass();
Method meth1 = objClass.getDeclaredMethod(stack.pop());

I'm missing the part of invoking the method with the variable args remaining in the stack. Any help ?





Aucun commentaire:

Enregistrer un commentaire