At the start, let me point out that in Mathematica 8, J/Link no
longer overloads Set. An internal kernel mechanism was created that,
among other things, allows J/Link to avoid the need for special, er,
"tricks" with Set.
J/Link has overloaded Set from the very beginning, almost twelve
years ago. This allows it support this syntax for assigning a value
to a Java field:
javaObject@field = value
The overloaded definition of Set causes a slowdown in assignments of the form
_Symbol[_Symbol] = value
Of course, assignment is a fast operation, so the slowdown is small
in real terms. Only highly specialized types of programs are likely
to be significantly affected.
The Set overload does _not_ cause a call to Java on assignments that
do not involve Java objects (this would be very costly). This can be
verified with a simple use of TracePrint on your a[b]=c.
It does, as you note, make a slight change in the behavior of
assignments that match _Symbol[_Symbol] = value. Specifically, in
f[_Symbol] = value, f gets evaluated twice. This can cause problems
for code with the following (highly unusual) form:
f := SomeProgramWithSideEffects[]
f[x] = 42
I cannot recall ever seeing "real" code like this, or seeing a
problem reported by a user.
This is all moot now in 8.0.
At 04:45 AM 5/3/2011, DrMajorBob wrote:
>Calls to Java are made for ABSOLUTELY everything Mathematica does, are
>they not?
Actually, calls to Java are made for a comparatively small set of
things in Mathematica. The vast majority of Mathematica programs will
never trigger a single call into Java.
Todd Gayley
Wolfram Research