Reputation: 65
What’s the best way to invoke a method by reflection using GWT, I know that there are some frameworks like "GWT Reflection" but I really want to hear some feedback about this. How is the best way to convert something like this:
GreetingServiceAsync service = GWT.create(GreetingService.class);
AsyncCallback callBack = new AsyncCallback< Void>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(Void result) {
}
};
service.doSomething(callBack);
in:
GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
String methodName = “doSomething”;
Object service;
AsyncCallback callBack = new AsyncCallback< Void>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(Void result) {
}
};
/*somehow invoke by reflection*/
Class<?> c = Class.forName(GreetingServiceAsync.class.getName());
Method method = c.getMethod(methodName, AsyncCallback.class);
method.invoke (service, callBack);
Many thanks, Luis.
Upvotes: 1
Views: 468
Reputation: 9537
Javascript 101 - there is no concept of reflection. GWT java translates to javascript. So gwt does not provide reflection support. Every other library that states gwt reflection in their homepage are just addressing a corner functionality and mis-stating their feature.
Upvotes: 2