我正在尝试使用JSO的package-private ::new()
方法在JSNI方法体内实例化java类型,但所有实例都作为null句柄返回。
怎么来的?
是否可以使用与Java类似的语法实例化该类?
以下是相关代码:
public class OnChangeHandlerJso extends JavaScriptObject {
protected OnChangeHandlerJso() {};
public static native JavaScriptObject create() /*-{
return function(cm, changeInfo) {
var eventBus = @com.gigaspaces.codemirror_gwt.client.events.EventUtils::CODE_MIRROR_EVENT_BUS;
var event = @com.gigaspaces.codemirror_gwt.client.events.EditorContentChangeEvent::new()();
// could something like this work?
// var event = new @com.gigaspaces.codemirror_gwt.client.events.EditorContentChangeEvent;
event.@com.gigaspaces.codemirror_gwt.client.events.EditorContentChangeEvent::setCm(Lcom/gigaspaces/codemirror_gwt/client/jsni/CodeMirrorJso;)(cm);
event.@com.gigaspaces.codemirror_gwt.client.events.EditorContentChangeEvent::setChangeInfo(Lcom/gigaspaces/codemirror_gwt/client/jsni/ChangeInfoJso;)(changeInfo);
eventBus.@com.google.gwt.event.shared.EventBus::fireEvent(Lcom/google/gwt/event/shared/GwtEvent;)(event);
};
}-*/;
}
答案 0 :(得分:0)
像这样解决:
public class OnChangeHandlerJso extends JavaScriptObject {
protected OnChangeHandlerJso() {};
public static native OnChangeHandlerJso create() /*-{
return function(cm, changeInfo) {
@com.gigaspaces.codemirror_gwt.client.vo.OnChangeHandler::handle(Lcom/gigaspaces/codemirror_gwt/client/jsni/CodeMirrorJso;Lcom/gigaspaces/codemirror_gwt/client/jsni/ChangeInfoJso;)(cm, changeInfo);
};
}-*/;
}
public class OnChangeHandler implements JsoWrapper<OnChangeHandlerJso> {
public static void handle(CodeMirrorJso cmJso, ChangeInfoJso changeInfoJso) {
// ...
EventUtils.CODE_MIRROR_EVENT_BUS.fireEvent(new EditorContentChangeEvent(cm, changeInfo));
}
}