问题
Java Code
package org.something;
public class myClass{
static public Double getAvg(){
//Returns an average
}
}
JavaScript Code
var aJavaClass = Java.type('org.something.myClass');
var avg = aJavaClass.getAvg();
This is pretty much what I am attempting to do. The application I'm creating requires the Java portion to transfer a Double to JavaScript for use in an embedded browser. I'd looked into Nashorn and several tutorials for it, but while their code is fine, mine fails to run correctly whenever aJavaClass is declared. Without this line, everything works.
To this point, the only thing I can think of is there being an import issue, but I'm not certain on how to test that.
Is there any reason why JS would not be recognizing my class?
来源:https://stackoverflow.com/questions/24965194/how-to-instantiate-a-java-class-in-javascript-using-nashorn