2

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?

1 Answer 1

7

Ok this worked for me:

ScriptObjectMirror result = (ScriptObjectMirror) function.invokeFunction("nameGen", 10);
        String[] strings = result.to(String[].class);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.