问题
My JavaScript code gives me an array of arrays of float
values:
var serverData = new Array();
var fArray = new Array();
// .. calc mx and my here
fArray.push(mx);
fArray.push(my);
this.serverData.push(fArray);
var out = window.letServerWork(this.serverData);
which I want to work with on the server. this.serverData
will look something like this:
{
0: 0: 1.123
1: 1.459
1: 0: 0.543
1: 1.679
2: 0: 1.157
1: 0.987
}
Therefore I need to know the right signature for this call. This here:
public static native void exportDoLinearRegression() /*-{
$wnd.letServerWork = $entry(@ew.server.algorithm.LinearRegression::doLinearRegression(Lcom/google/gwt/core/client/JsArray<Lcom/google/gwt/core/client/JsArrayNumber;>;));
}-*/;
is wrong, but it should look something like this. Does anybody know how the signature has to look like so that this works?
Thank you!
回答1:
It turned out, that it's not necessary to tell about the generic type. The GWT compiler is happy if it knows that there will be a JsArray
. The Java function then defines the generic type. This is how it worked for me:
public static String doLinearRegression(JsArray<JsArrayNumber> points) {
for(int i = 0; i < points.length(); i++) {
System.out.println(points.get(i).get(0) + " " + points.get(i).get(1));
// do stuff
}
return result;
}
public static native void exportDoLinearRegression() /*-{
$wnd.letServerWork = $entry(@ew.server.algorithm.LinearRegression::doLinearRegression(Lcom/google/gwt/core/client/JsArray;));
}-*/;
来源:https://stackoverflow.com/questions/16701465/jsni-jsarrayjsarraynumber-type-signature