Reputation: 129
I am using GWT and have a Java method with a signature that requires a string and a boolean parameter, like this:
private void myMethod(String s, Boolean b) {}
I have a JSNI method that exposes this Java method after compilation:
public class myClass {
public native void exportMyMethod(myClass c)/*-{
$wnd.myMethod = $entry(function(s, b) {
[email protected]::myMethod(Ljava/lang/String;Z);
});
}-*/;
}
For the life of me, I cannot figure out how to properly format the param-signature when there's more than 1 parameter.
I've read the GWT documentation regarding how to do this. I've also read where that document directs me to how to properly refer to the JNI Type. But I cannot seem to find an example of how to format the signature when using more than 1 parameter. It seems like it should be easy.
So, how do I format my param-signature correctly? I've tried:
Every different permutation that I've tried has resulted in the same error.
"Referencing method 'com.path.to.myClass.myMethod(Ljava/lang/String;Z)/' unable to resolve method."
Upvotes: 1
Views: 1109
Reputation: 64541
A class reference starts with an L
and ends with a ;
, and argument types aren't separated; so only the first two signatures are well-formed:
[email protected]::myMethod(Ljava/lang/String;Z);
[email protected]::myMethod(Ljava/lang/String;Ljava/lang/Boolean;);
The first one takes a boolean
, the second a java.lang.Boolean
.
Upvotes: 2
Reputation: 18331
In Javascript, unlike Java, you can actually pass a method as if it were a variable - you can reassign it, assign it to a variable, etc. That means that for JSNI references to work, we need to have a way not only to call them, but to reference them.
The standard JSNI pattern then is [email protected]::method(arg;types;)(actual, params)
In your case, this line
[email protected]::myMethod(Ljava/lang/String;Z);
should be changed to something like this
[email protected]::myMethod(Ljava/lang/String;Z)(s, b);
Please note however that Z
refers to boolean
, not Boolean
, so the current code in your question is inconsistent. If only one method exists with a particular name, you can omit the types and just pass *
:
[email protected]::myMethod(*)(s, b);
Upvotes: 5