Final array is being changed

The 1st example explains at its comments why the 2nd 1 works. :wink:

Processing got nothing to do w/ that, but the Java language itself! :coffee:

As you know by now, the 1st example already got those basic insights. :roll_eyes:

Basically, we can have more than 1 variable (and array slots) pointing at the same object.
They simply become alias for the same object. :flushed:

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 the same memory address of that object. :confused:

So when we clone an object, we can’t use the assignment = operator (or just an arrayCopy()) alone. :drooling_face:

We need to check whether that object offers a clone() method, or some other analogous 1. :cowboy_hat_face:

This way we get another object (and thus a diff. memory address value), but w/ the same content as the original 1. :star_struck:

2 Likes