How to copy an array

I’m used to apply final to any variable I don’t want to be re-assigned.

We can’t re-assign final variables by accident.

Also b/c a final variable got its value permanently sealed we can rest assured when its value is read that will be always the same.

Well, pretty much nothing really.

Of course we’ll have to remove the final keyword when we change our mind and need the variable to be re-assignable again.

On C-based programming languages like Java & JS even the assignment = operator can be used within an expression.

I’ve just felt like to use that feature there.

I couldn’t do that in Python btW.

The way expression b = (a = arr).clone(); works is 1st field a receives the value of parameter arr.

Right after that method clone() is invoked on that same reference value creating a shallow copy of the array which field a now references to.

Finally field b receives the reference value of that cloned array.