user1226162
user1226162

Reputation: 2042

JSNI (call from javascript to java)

In the JSNI example to call a Java method from Javascript, they write this:

$wnd.testJSNI = @com.jsni.client.HelloJSNI::testJSNI(Ljava/lang/String;)(test);

I tried to figure it out, but couldn't find what exactly is meant by Ljava/lang/String? Am I required to pass these arguments?

Upvotes: 0

Views: 1693

Answers (2)

CodeChimp
CodeChimp

Reputation: 8154

That 'Ljava/lang/String;" format looks like JNI. It's used to describe, in text, a data type. You can read more here.

Upvotes: -1

Jason Hall
Jason Hall

Reputation: 20930

The Ljava/lang/String; tells GWT that the method expects a String parameter, which will be passed in as the test value in your sample code.

In general in JSNI methods you need to tell GWT what the parameter types are, or you can use the shortcut (*) which tells GWT to figure it out for itself. This works in most cases as far as I've seen. So your code could also be written as:

var test = 'This is my test string';
$wnd.testJSNI = @com.jsni.client.HelloJSNI::testJSNI(*)(test);

Upvotes: 3

Related Questions