2

I am using GWT and I have created a native method that calls the method cmd_addspace in the class EverlinkedActions and it works fine for now:

private static native String execute(String functionName,  Object[] vParams)/*-{
  try{          
      @es.gwt.client.dash.actions.impl.EverlinkedActions::cmd_addspace([Ljava/lanG/Object;)(vParams);          
  }catch(e){
      alert(e.message);
  }

}-*/;

How can i make the method name dynamic? it means instead of "cmd_addspace" i want to call the method "functionName" which its name is passed as argument in the native method.

And is their a way to make the class name also dynamic? i want to have something like that:

private static native String execute(String className, String functionName,  Object[] vParams)/*-{
  try{          
      @es.gwt.client.dash.actions.impl.className::functionName([Ljava/lanG/Object;)(vParams);          
  }catch(e){
      alert(e.message);
  }

}-*/;

Thanks for any help

user2318955
  • 85
  • 10
  • did you want to call a Java function or JavaScript method? If Java, you could call a generic method in Java, pass in the name and use reflection. http://stackoverflow.com/questions/160970/how-do-i-invoke-a-java-method-when-given-the-method-name-as-a-string –  May 09 '13 at 13:56
  • Thanks for the link. I have tried it but i was obtaing this error: java.lang.reflect.Method cannot be called in client side – user2318955 May 09 '13 at 14:01
  • Oh, I forgot GWT doesn't implement Reflection. –  May 09 '13 at 14:07
  • Sounds like the OP is trying to implement Reflection him/herself! – funkybro May 09 '13 at 16:21

1 Answers1

4

Not sure what you're trying to actually achieve here but I'm afraid JSNI doesn't work like that.

Code such as @es.gwt.client.dash.actions.impl.EverlinkedActions::cmd_addspace([Ljava/lanG/Object;)(vParams); needs to be a fully resolvable symbol at compile time because class and method names get replaced with their minimised versions.

funkybro
  • 7,633
  • 5
  • 34
  • 46