If I have a JS function
that returns an array of strings, how should I go about casting it to a useful type (I'm thinking either a Java array or Collection class)? I've noticed that the return type is always a ScriptObjectMirror
which has an interesting to(Class<?> clazz)
method, but I'm uncertain on it's use. I've checked several other StackOverflow questions, but none were useful. Can you show an example?
Ok this worked for me:
ScriptObjectMirror result = (ScriptObjectMirror) function.invokeFunction("nameGen", 10);
String[] strings = result.to(String[].class);
来源:https://stackoverflow.com/questions/29452758/casting-array-result-from-javascript-to-something-useful-using-scriptobjectmirro