0
GWT中可能在客戶端和服務器上有不同的函數實現嗎?例如,GWT:客戶端/服務器條件編譯
private static native String toFixedNative(int digits, double value) /*-{
return value.toFixed(digits);
}-*/;
public static String toFixed(int digits, double value) {
if (GWT.isClient()) {
return toFixedNative(digits, value);
} else {
String format = "%." + digits + "f";
return String.format(Locale.US, format, value);
}
}
這並不目前的工作,GWT編譯器抱怨,那String.format
功能不可用在GWT。但它並不是真的需要,因爲String.format
僅在!GWT.isClient()
時才被調用。
有什麼辦法可以告訴GWT編譯器忽略該函數的一部分嗎?
'@ GwtIncompatible'不起作用:如果我換'String.format'爲'@GwtIncompatible formatWrapper()',GWT編譯器只是不看'formatWrapper'方法,因而仍抱怨它'toFixed '。 – stepancheg
超級來源應該可以工作。 – stepancheg