java - New ArrayList() on Child Object does not update reference in parent object -


i thought based on references in java. have complex object contains child list.

parentobj |-- ... |-- list<string> childlist 

when modify childlist directly, see "parentobj" updates childlist reference accordingly.

childlist.add("hello"); 

but when do

if (childlist == null) {   childlist = new arraylist<string>(); } 

i see "parentobj" still has null child list! different case, expecting parentobj reference updated setting/adding.

java passes references value. meaning there's duplicate of reference that's passed method argument. when assign childlist , if it's not original reference assignment done duplicate reference.

that's why should using setter method.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -