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:
- [email protected]::myMethod(Ljava/lang/String;Z);
- [email protected]::myMethod(Ljava/lang/String;Ljava/lang/Boolean;);
- [email protected]::myMethod(Ljava/lang/StringLjava/lang/Boolean;);
- [email protected]::myMethod(Ljava/lang/String;,Ljava/lang/Boolean;);
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."
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
should be changed to something like this
Please note however that
Zrefers toboolean, notBoolean, 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*: