Are parameters passed by value or by reference?
All parameters (values of primitive types and values that are references to objects) are passed by value. However this does not tell the whole story, since objects are always manipulated through reference variables in Java. Thus one can equally say that objects are passed by reference (and the reference variable is passed by value). This is a consequence of the fact that variables do not take on the values of “objects” but values of “references to objects” as described in the previous question on linked lists. Bottom line: The caller’s copy of primitive type arguments (int, char, etc.) _do not_ change when the corresponding parameter is changed. However, the fields of the caller’s object _do_ change when the called method changes the corresponding fields of the object (reference) passed as a parameter. • (Sect. 6) What are “class literals”? A feature introduced in JDK 1.1. They are literals of type “Class” that hold a value representing any class. There are even values to represent “vo
All parameters (values of primitive types and values that are references to objects) are passed by value. However this does not tell the whole story, since objects are always manipulated through reference variables in Java. Thus one can equally say that objects are passed by reference (and the reference variable is passed by value). This is a consequence of the fact that variables do not take on the values of “objects” but values of “references to objects” as described in the previous question on linked lists. Bottom line: The caller’s copy of primitive type arguments (int, char, etc.) _do not_ change when the corresponding parameter is changed. However, the fields of the caller’s object _do_ change when the called method changes the corresponding fields of the object (reference) passed as a parameter. • (Sect. 6) What are “class literals”? A feature introduced in JDK 1.1. They are literals of type “Class” that hold a value representing any class.