Java编程语言和Java指南中关于Java的参数传递的解释

From The Java Programming Language, by James Gosling et al. 3rd edition (pg.
56):
quote:
Some people will say incorrectly that objects are passed "by reference."In programming language design, the term pass by reference properly means that when an argument is passed to a function, the invoked
function gets a reference to the original value, not a copy of its value. If the function modifies its parameter, the value in the calling code will be changed because the argument and parameter use the same slot in
memory. The Java programming language does not pass objects by reference; it passes object references by value. Because two copies of the same reference refer to the same actual object, changes made
through one reference variable are visible through the other. There is exactly one parameter passing mode -- pass by value -- and that helps keep things simple.


From The Java Tutorial
quote:
Pass by Value
In Java methods, arguments are passed by value. When invoked, the method receives the value of the variable passed in. When the argument is of primitive type, pass -by-value means that the method
cannot change its value. When the argument is of reference type, pass-by-value means that the
method cannot change the object reference, but can invoke the object's methods and modify the accessible variables within the object. This is often the source of confusion--a rogrammer writes a method that attempts to modify the value of one its arguments and the method doesn't work as expected.
Let's look at such method and then investigate how to change it so that it does what the programmer originally intended. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值