Pointers and references: Difference between revisions

Content deleted Content added
→‎{{header|Java}}: this is completely incorrect; Strings are immutable; re-wrote section
Line 232: Line 232:
}
}


Java's is always call-by-value; hence, it is not possible to change the value of the variable of the caller that is passed in, whether it is a primitive or a reference. However, as noted above, if the object that the reference is pointing to is mutable, then it is possible to modify that object's state through the reference; and if the calling function has a reference to the same object they will see that modification through the reference.
Java's is always call-by-value; hence, it is not possible to change the value of the variable of the caller that is passed in, whether it is a primitive or a reference. However, as noted above, if the object that the reference is pointing to is mutable, then it is possible to modify that object's state through the reference; and if the calling function has a reference to the same object they will see that modification through the reference. So if you want to reflect changes in an argument back to the caller, one thing that you can do is wrap the argument as a field in an object; then modify the object through the reference.


=={{header|Perl}}==
=={{header|Perl}}==