I have declared the following class:
public class JsniTest<T> {
private Map<T, String> map;
public JsniTest(Map<T, String> map) {
this.map = map;
}
public String get(T rowKey) {
return map.get(rowKey);
}
}
and the following "main" class:
public class TheApp implements EntryPoint {
public void onModuleLoad() {
final Map<Integer, String> map = new HashMap<Integer, String>();
map.put(0, "test");
final JsniTest<Integer> test = new JsniTest<Integer>(map);
final String result = testJsni(test, 0);
}
public native String testJsni(JsniTest x, int key) /*-{
return x.@com.test.client.JsniTest::get(Ljava/lang/Object;)(key);
}-*/;
}
When I run this code on Gwt 2.5.1 in debug mode I get the following exception:
SEVERE: invoke arguments: JS value of type number, expected java.lang.Object
java.lang.IllegalArgumentException: invoke arguments: JS value of type number, expected java.lang.Object
at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:178)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:65)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
Is it possible to invoke the get method of JsniTest and receive the proper result? What are my options? The JsniTest class is just a replacement for the real class I need to use, over which I have no control as it is a third party library class. I could possibly wrap it with a wrapper class that would work for any T. I have full control over TheApp class and the testJsni method. Thanks for your help.