If how reference behaves under Java was the reason why Java isn’t liked much folks would also hate JavaScript, Python and almost all modern programming languages!
Actually programmers tend to dislike Java b/c we have to explicitly declare the datatype of each single variable just like old C/C++ do!
BtW I’ve got some previous posts about Java’s reference aliases below:
Variables/fields/parameters store a single value.
They range from 1 byte to 8 bytes in most languages.
At the statement m = new PVector(); the operator new creates a contiguous memory block enough to fit in all PVector’s non-static fields.
And when it’s done, it returns the 1st memory address of that block.
And finally, that 1st memory address is stored in the field m as a reference value.
Now, when you do pressLoc = m, you’re assigning field pressLoc w/ the exact value of m.
After that assign…
The 1st example explains at its comments why the 2nd 1 works.
Processing got nothing to do w/ that, but the Java language itself!
As you know by now, the 1st example already got those basic insights.
Basically, we can have more than 1 variable (and array slots) pointing at the same object.
They simply become alias for the same object.
That is, if we mutate an object via 1 of its alias, its other aliases see those changes as well, b/c they all store th…
Actually JS functions, just like Java’s, are ALWAYS pass by value, regardless it’s a primitive or object datatype.
When we pass a variable as a single argument to a function, the current value stored in that variable is read, and then the invoked function’s receiving parameter is initialized w/ a copy of that read value.
B/c a function’s parameter can only receive a copy of the current value stored in a passed variable, reassigning another value to that local parameter won’t replace the value…
1 Like