什么是在GWT中通过Reflection调用方法的最佳方法

时间:2013-01-11 14:46:09

标签: gwt reflection

使用GWT通过反射调用方法的最佳方法是什么,我知道有一些框架,如“GWT Reflection”,但我真的想听到一些关于此的反馈。 如何转换这样的东西是最好的方法:

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);

非常感谢, 路易斯。

1 个答案:

答案 0 :(得分:2)

Javascript 101 - 没有反思的概念。 GWT java转换为javascript。所以gwt不提供反射支持。在其主页中声明gwt反射的每个其他库只是解决角落功能并错误地说明其功能。