@JsExport@JsType@JsNamespace("foo")public class Dispatcher { public String dispatch(String action, Payload payload){ if("action1".equals(action)) return dispatchWithCast(payload); return "Unknown action: " + action; } public String dispatchWithCast(Payload payload){ ConcretePayload w = (ConcretePayload) payload; return w.foo; }}
@JsExport@JsTypepublic class Payload {}
@JsExport@JsTypepublic class ConcretePayload extends Payload { public String foo; public int bar;}var test = new foo.Dispatcher();alert("Dispatch: " + test.dispatch("action1", {"foo": "a", "bar": 2})); // Uncaught java.lang.ClassCastExceptionI am using GWT 2.8.0-SNAPSHOT, but the new annotations does not work for me.I tried using @JsType(namespace = "acme", name = "MyJavaScriptObject"), as described in the new version of the JsInterop document, but apparently the namespace and name attributes are not there in the jar file.Same thing with the @JsExport and @JsNamespace, I currently have to use them or things stop working.
function com_google_gwt_lang_Cast_canCast__Ljava_lang_Object_2Lcom_google_gwt_core_client_JavaScriptObject_2Z(src_0, dstId){ return typeof src_0 === 'string' && !!com_google_gwt_lang_Cast_stringCastMap[dstId]
|| src_0.java_lang_Object_castableTypeMap && !!src_0.java_lang_Object_castableTypeMap[dstId]
|| typeof src_0 === 'number' && !!com_google_gwt_lang_Cast_doubleCastMap[dstId]
|| typeof src_0 === 'boolean' && !!com_google_gwt_lang_Cast_booleanCastMap[dstId];}--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
--
// in Javapackage com.acme;
@JsType(isNative = true)interface Foo {}
@JsType(isNative = true)class Baz implements Foo{ public int qux;}
class Bar { @JsMethod public static int action(Foo foo) { Baz baz = (Baz) foo;
return baz.qux;
}}
// in JavaScript
var baz = { qux: 42 };com.acme.Bar.action(baz); // will return 42!//In Java
package com.acme;
@JsTypepublic class IntParser { public static int parseArray(String[] args) { return Integer.parseInt(args[0]); }}
//In Javascript
var num = com.acme.IntParser.parseArray(["42"]); // Should return 42, but throws 'Uncaught [object Object]'!
@JsType(namespace = JsPackage.GLOBAL)
public static class IntParser {
public static int parseArray(String[] args) {
return Integer.parseInt(args[0]);
}
}
public void testStringArray() {
assertEquals(42, callIntParser());
}
private native int callIntParser() /*-{
return $wnd.IntParser.parseArray(["42"]);
}-*/;