我想将 GWT JSO属性名称定义为 JSO 中的常量,以避免拼写错误并从 Eclipse 代码完成中受益,如下所示:
public final class MyJSO extends JavaScriptObject
{
/** here is the constant */
private static final String MY_CONST = "myPropName";
protected MyJSO() {
super();
}
public native void setMyProp(final boolean pFlag)
/*-{
this.@fully.qualified.MyJSO::MY_CONST = pFlag;
}-*/;
public native boolean isMyProp()
/*-{
if (this.hasOwnProperty(@fully.qualified.MyJSO::MY_CONST)) {
return this.@fully.qualified.MyJSO::MY_CONST;
} else {
return false;
}
}-*/;
}
GWT 编译器应该能够在编译时从常量中替换 String,因此以后作为 Javascript 存在的对象没有问题。
但这完全行不通,我想我可能错了。:-) 谁能解释为什么?你有更好的想法如何实现这一目标?
谢谢!