|
References and Values
J/Link provides a mapping between certain Mathematica expressions and their Java counterparts. What this means is that these Mathematica expressions are automatically converted to and from their Java counterparts as they are passed between Mathematica and Java. For example, Java integer types (long, short, int, and so on) are converted to Mathematica integers and Java real types (float and double) are converted to Mathematica real numbers. Another mapping is that Java objects are converted to JavaObject expressions in Mathematica. These JavaObject expressions are references to Java objects—they have no meaning in Mathematica except as they are manipulated by J/Link. However, some Java objects are things that have meaningful values in Mathematica, and these objects are by default converted to values. Examples of such objects are strings and arrays.
One could say, then, that Java objects are by default returned to Mathematica "by reference," except for a few special cases. These special cases are strings, arrays, complex numbers (discussed later), BigDecimal and BigInteger (discussed later), and the "wrapper" classes (e.g., java.lang.Integer). You could say that these exceptional cases are returned "by value." The table in Section 1.1.4 shows how these special Java object types are mapped into Mathematica values.
In summary, every Java object that has a meaningful value representation in Mathematica is converted into this value, simply because that is the most useful behavior. There are times, however, when you might want to override this default behavior. Probably the most common reason for doing this is to avoid unnecessary traffic of large expressions over MathLink.

"By reference" and "by value" control.
|