JSNI and method signature

784 views
Skip to first unread message

Pavel Byles

unread,
Apr 2, 2010, 2:57:56 PM4/2/10
to Google-Web-Toolkit
Can someone show me the method signature for the following Java method ?:

public static void myJavaMethod(JsArray<MyJsObject> jso) { ... }

My JsObject's class:
public class MyJsObject extends JavaScriptObject { ... }

JsArray's class:
class JsArray<E extends JavaScriptObject> extends JavaScriptObject {
protected JsArray() { }
public final native int length() /*-{ return this.length; }-*/;
public final native E get(int i) /*-{ return this[i]; }-*/;
}


When I do this:
$wnd.myJavaMethod =
        @com.xxxx.xxxxx.client.GfcJs::myJavaMethod(Lcom/xxxx/xxxxx/client/JsArray<Lcom/xxxx/xxxxx/client/MyJsObject;>;);

I get the following error:
JavaScript parsing: Expected a valid parameter type signature in JSNI method reference.

--
-Pav

kozura

unread,
Apr 2, 2010, 4:24:33 PM4/2/10
to Google Web Toolkit
Remove the generics (<Lcom...;>) from the signature.

On Apr 2, 12:57 pm, Pavel Byles <pavelby...@gmail.com> wrote:
> Can someone show me the method signature for the following Java method ?:
>
> public static void myJavaMethod(JsArray<MyJsObject> jso) { ... }
>
> My JsObject's class:
> public class MyJsObject extends JavaScriptObject { ... }
>
> JsArray's class:
>
> class JsArray<E extends JavaScriptObject> extends JavaScriptObject {
>   protected JsArray() { }
>   public final native int length() /*-{ return this.length; }-*/;
>   public final native E get(int i) /*-{ return this[i];     }-*/;
>
> }
>
> When I do this:
> $wnd.myJavaMethod =
>

> @com.xxxx.xxxxx.client.GfcJs::myJavaMethod(Lcom/xxxx/xxxxx/client/JsArra*y*

Pavel Byles

unread,
Apr 6, 2010, 9:41:51 AM4/6/10
to google-we...@googlegroups.com
Thanks Kozura,
that worked. However, Eclipse auto-completes with the generics stuck in there.

Also what happens if I have two java signatures:
public static void myJavaMethod(JsArray<MyJsObject> jso) { ... }
public static void myJavaMethod(JsArray<MyJsObject2> jso) { ... }

How will the javascript know which method to call if the generics aren't included?

--
Pavel

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.




--
-Pav

kozura

unread,
Apr 6, 2010, 9:45:31 AM4/6/10
to Google Web Toolkit
Java doesn't include generics in the signature, it's simply a compile
time check. Try it, you can't actually make those two methods in the
same scope.

Pavel Byles

unread,
Apr 6, 2010, 10:10:35 AM4/6/10
to google-we...@googlegroups.com
But my call to both java methods will be:
@com.xxxx.xxxxx.client.GfcJs::myJavaMethod(Lcom/xxxx/xxxxx/client/JsArray;);

which java method will it call?

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.




--
-Pav

kozura

unread,
Apr 6, 2010, 10:20:42 AM4/6/10
to Google Web Toolkit
Java simply won't allow you to create both of those methods in the
same class, because it considers them to have the same signature.

On Apr 6, 8:10 am, Pavel Byles <pavelby...@gmail.com> wrote:
> But my call to both java methods will be:

> @com.xxxx.xxxxx.client.GfcJs::myJavaMethod(Lcom/xxxx/xxxxx/client/JsArra*y*

Pavel Byles

unread,
Apr 6, 2010, 10:31:41 AM4/6/10
to google-we...@googlegroups.com
Ah I see.
ok. Thanks for all the help!

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.




--
-Pav
Reply all
Reply to author
Forward
0 new messages