0

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?

2 Answers 2

3

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);
Sign up to request clarification or add additional context in comments.

Comments

-1

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

3 Comments

It's not JNI, it's JSNI which is GWT specific.
I understand, but that format is from JNI, which is dealing with cross-language data types. I am guessing they are re-using the same nomenclature for JSNI, which is doing the same thing (calling code from one language from another language), and needs to know what data type you are sending.
agreed, JNI is used under the hood, and those types are being declared this way for the JVM. +1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.