开发者

Pass by value in Java [duplicate]

开发者 https://www.devze.com 2023-02-07 10:57 出处:网络
This question already has answers here: 开发者_运维知识库 Closed 12 years ago. Possible Duplicates:
This question already has answers here: 开发者_运维知识库 Closed 12 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号