rhino-script-engine
rhino-script-engine copied to clipboard
Static String returning methods from Imported classes are returning an object instead of a string
I am running a little script importing a static class using this library as dependency on my Java 11 project. The return type of the function is object instead of a string how it used to be on my old project version using the Java 7 embedded Rhino Script Engine. So, I need to cast every function return to String in order to use the prototype functions of String.
try {
var ImportedClasses = JavaImporter(com.StringUtils);
with (ImportedClasses) {
var text = 'Test text';
document.write ('<br>typepf text: '+typeof text+'<br>');
var shouldBeString = StringUtils.methodReturningString ();
document.write ('<br>typepf shouldBeString: '+typeof shouldBeString+'<br>');
}
}
catch (e) {
document.write (e);
}
This script will print the following:
typepf text: string
typepf shouldBeString: object