immutability - Mutability of arrays in java -


if method returns object particular array index, , object modified, object modified locally or object in array modified?

is there way force each case?

the object in array modified. works way because, although java pass value, it's passing value of object reference. in end array has copy of reference , whatever gets result has copy of reference. when modify object itself, you're modifying thing both "point" to. both see change.

the way make not true make copy of element before return it.

alternatively, if make object immutable, don't have worry these details because can't change object in first place.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -