A semantics of passing an argument to a method in which a copy of the actual argument value is taken and placed in a separate memory location, represented by the corresponding formal argument. As a result, assignment to a formal argument within a method can have no effect on the value stored in the actual argument. This principle is often misunderstood in Java. It does not mean that an object referred to by an actual argument cannot be modified via the formal argument. Consider the following example of sorting the array referred to by the variable
sortmethod will change the order of the values stored in the object referred to by
numbers. However, it is impossible for the
sortmethod to change which array
numbersrefers to - a sorted copy, for instance. Some languages provide an argument passing semantics known as call-by-reference, in which an actual argument's value may be changed. Java does not provide this, however.
- Browse Related Terms: actual argument, actual parameter, actual parameter list, anonymous array, anonymous object, argument, call-by-value, command-line argument, constructor, copy constructor, formal argument, formal parameter, formal parameter list, instanceof, method, method header, method overriding, parameter
Also listed in: