Sarah Szabo
Sarah Szabo

Reputation: 10815

Casting Array Result From JavaScript to Something Useful Using ScriptObjectMirror

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?

Upvotes: 2

Views: 1914

Answers (1)

Sarah Szabo
Sarah Szabo

Reputation: 10815

Ok this worked for me:

ScriptObjectMirror result = (ScriptObjectMirror) function.invokeFunction("nameGen", 10);
        String[] strings = result.to(String[].class);

Upvotes: 7

Related Questions