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

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -