Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? [Re:臧圩人]
JiafanZhou



版主


发贴: 736
积分: 61
于 2008-07-15 16:11 user profilesend a private message to usersend email to JiafanZhousearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Hi,

I spent some time this morning reading this article and try to understand this article here, I found couple of issues.

- First, the example you provided is not very intuitive, i.e. really should put some text in the output. I have been trying scrolling down and up to link the targeted output.

- The language you use here is not very understandable, I heard you mentioned you wished to publish your own book about interviewing questions for Java programmers. I think you need to rewrite this article.
To be more specific, I try very hard to understand the following sentence:
方法的情况下,变量i和ParamTest型对象t的属性num具有相同的值,却是两个不同变量。变量i是由JAVA虚拟机创建的作用域在change(int i)方法内的局部变量,在这个方法执行完毕后,它的生命周期就结束了。
1. What do you mean by "方法的情况下"?
2. You haven't explained the "JVM作用域" before, people will be lost.
3. As a general, I understand this sentence but it is very bad structured.

- The images you attached here are not displayed, so I have no idea what you try to explain in those images.

- The code below, using an "&" sign, is that correct?
b &= false; 


- 最后我们得出如下的结论:

基本类型和基本类型变量被当作参数传递给方法时,是值传递。在方法实体中,无法给原变量重新赋值,也无法改变它的值。
对象和引用型变量被当作参数传递给方法时,是引用传递。在方法实体中,无法给原变量重新赋值,但是可以改变它所指向对象的属性。

Ok, this is *completely wrong*. Again, in Java, there is only Pass-by-value, there is *no* concept of pass-by-reference at all. The definition by "pass-by-reference" means the original object reference is passed into the method (like in C++), however, in Java, it passes a deep copy of the original object reference. Notice it is still "pass-by-value" although it is an object reference. Otherwise you have completely re-defined the Java programming language. (Passing the original object reference, and passing a copy of it are totally difference. ) The reason for this is provided as below:

Imagine that in an application that you have 100,000 method invocations which passing the same object reference, in C++ (could define as pass-by-reference), there will be only an single instance of it created in stack. Whereas in Java (pass-by-value) means 100,000 instances(values) will be generated accordingly in stack.

So as a general, you might consider to rewrite this article if possible.

Regards,
Jiafan



When I was a kid I used to pray every night for a new bike. Then I realized that The Lord doesn't work that way, so I stole one and asked him to forgive me.

话题树型展开
人气 标题 作者 字数 发贴时间
20202 JAVA面试题解惑系列(五)——传了值还是传了引用? 臧圩人 5121 2008-07-13 16:55
15172 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? billgacsli 266 2008-07-14 19:49
14483 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? JiafanZhou 562 2008-07-17 18:00
14642 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? 臧圩人 158 2008-07-17 20:19
14536 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? JiafanZhou 72 2008-07-18 15:39
13778 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? newfish 216 2008-09-22 15:25
14401 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? JiafanZhou 354 2008-09-25 16:39
14806 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? 臧圩人 33 2008-07-14 22:03
14944 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? billgacsli 29 2008-07-15 09:28
14634 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? JiafanZhou 2254 2008-07-15 16:11
14679 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? 臧圩人 548 2008-07-15 17:37
14679 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? JiafanZhou 2154 2008-07-16 16:05
14939 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? billgacsli 408 2008-07-16 15:05
14651 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? 臧圩人 152 2008-07-16 21:26
14708 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? 臧圩人 262 2008-07-16 21:30
14608 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? JiafanZhou 641 2008-07-17 15:53
14601 Re:JAVA面试题解惑系列(五)——传了值还是传了引用? 臧圩人 3 2008-07-17 17:14

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923