JiafanZhou
版主
发贴: 736
积分: 61
|
于 2008-07-15 16:11
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.
|