我正在尝试在我的GWT项目中提供一些函数挂钩:
private TextBox hello = new TextBox();
private void helloMethod(String from) { hello.setText(from); }
private native void publish() /*-{
$wnd.setText = $entry(this.@com.example.my.Class::helloMethod(Ljava/lang/String;));
}-*/;
Run Code Online (Sandbox Code Playgroud)
publish()被召入onModuleLoad().但这不起作用,在开发控制台中没有提供反馈的原因.我也尝试过:
private native void publish() /*-{
$wnd.setText = function(from) {
alert(from);
this.@com.example.my.Class::helloMethod(Ljava/lang/String;)(from);
}
}-*/;
Run Code Online (Sandbox Code Playgroud)
这将java.lang.ClassCastException在FireBug控制台中抛出一个,虽然alert火灾很好.建议?