- To use ReturnAsJavaObject, you first need to load J/Link using Needs["JLink`"].
- Most Java objects are returned as references normally, but those that have a meaningful Mathematica representation are returned "by value". Such objects include strings, arrays, and the so-called wrapper classes like java.lang.Integer. ReturnAsJavaObject overrides the normal behavior and forces any object returned to Mathematica to be sent only as a reference.
- Typically used to avoid needlessly sending large arrays of numbers back and forth between Java and Mathematica.
- You can use ReturnAsJavaObject to cause only a reference to be sent, then use the JavaObjectToExpression function at the end if the final value is needed.