Java Is Pass By Value
Posted by castever on June 29, 2009
This is something that threw me off when I first encountered it; I should have read the tutorial.
“Primitive arguments, such as an
intor adouble, are passed into methods by value. This means that any changes to the values of the parameters exist only within the scope of the method. When the method returns, the parameters are gone and any changes to them are lost.”“Reference data type parameters, such as objects, are also passed into methods by value. This means that when the method returns, the passed-in reference still references the same object as before. However, the values of the object’s fields can be changed in the method, if they have the proper access level.”
(reference: The Java Tutorial: Passing Information to a Method or Constructor)