Wolfram ResearchPRODUCTSPURCHASEFOR USERSCOMPANYOUR SITES
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.

Documentation / Mathematica / Add-ons & Links / J/Link / Part 1. Installable Java: Calling Java from Mathematica / ...Returning Objects "By Value" and "By Reference" /

JavaObjectToExpression

In the previous section, we saw how the ReturnAsJavaObject function can be used to cause objects normally returned to Mathematica by value to be returned by reference. It is necessary to have a function that does the reverse—takes a reference and converts it to its value representation. That function is JavaObjectToExpression.

Returning to the appendString() example above, we used ReturnAsJavaObject to avoid costly passing of string data back and forth over MathLink. The result of this was that the veryLongString variable now held a JavaObject expression, not a literal Mathematica string. JavaObjectToExpression can be used to get the value of this string object as a Mathematica string:

The majority of Java objects have no meaningful value representation in Mathematica. These objects can only be represented in Mathematica as JavaObject expressions, and using JavaObjectToExpression on them has no effect.

The ReturnAsJavaObject function is not the only way to get a JavaObject expression for an object that is normally returned to Mathematica as a value. The JavaNew function always returns a reference:

The next section introduces the MakeJavaObject function, which is easier than using JavaNew to construct Java objects out of Mathematica strings and arrays.



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information


 © 2008 Wolfram Research, Inc.  Terms of Use  Privacy Policy | [ja] |
Sign up for our newsletter: