Pass by value in Java [duplicate]
Possible Duplicates:
Does Java pass by reference? Is Java pass by reference?
Hey,
Is it true that Java
passes everything by value
, and we can't pass something by reference
?
Thanks.
Good God, it can't be asked again. Java is pass by value - always, in all cases. That's it.
Here's a reference that quotes James Gosling, who should be authoritative enough for anyone:
From the authors of Java: "There is exactly one parameter passing mode in Java - pass by value - and that helps keep things simple." The Java Programming Language, 2nd ed. by Ken Arnold and James Gosling, section 2.6.1, page 40, 3rd paragraph.
Java passes value of references of the objects you are passing and simple value for primitive types. See following discussion on this: Is Java pass by reference?
Java passes primitives by value by default, and all types have their object references passed by value. See http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.3.1 for details.
精彩评论