Java is pass by reference and pointer eliminated?
In many blogs and documents, people will say, Java is already eliminat pointer, hence what java pass as parameter is value, the
thing that pass through method parameter list is named
Let us review what reference and point like in C/C++, which is the most standard stem of program
100 100 100 20 20 20 50 50 50 70 70 70 70 3 70 3 3 3
from this instance, we got to know three things:
- variable, pointer and reference have the capability to change the value of variable.
- pointer is a kind of method that will affect variable it pointed to, but it can not change value if this pointer is pointing to another variable (sounds like bullshit!).
- reference is a kind of alias that also behave like pointer, but what alias mean is the variable and reference are binded together, when reference or variable changed, the other one also varied.
After review pointer and reference behavior in C++, now let us see what that behave in
What do you think of the system print are?
According to definition of
reference, the result should be:
outer before Rugal inner before Rugal inner after Bernstein outer after Bernstein
also, official document said that in java, the thing that passed is called
reference, which ambiguously confused many java developer.
pitfally, the actual print is:
outer before Rugal inner before Rugal inner after Bernstein outer after Rugal
outer after Rugal means inner
original ref is not the same thing in outer
which is not an alias like
referece in C++.
Do you feel puzzled? because they said java is passed by value, and there is no more pointer. what is wrong with you? what is wrong with me?
To keep you clarified, Let me explain this to you
there is no one to gurrantee
reference in java is what
reference like in
Don’t you think this so called
reference in java behave just like what pointer do in
now you got to know that
Java reference is what pointer behave in
Even if official documentation demonstrated there is no more pointer in Java, and the thing pass through method is called
reference is a mendacity, or maybe it is just a conception that result from ambiguity, nobody knows
Thus let us make a deal, that Java is pass-by-value, because what passed into parameter list is the actual address value of a object.
But here is a thing, all the so called
reference in java is not what
reference behave in C++, it is more likely with
pointer. nevertheless, this
pointer do not have the capability to dereference the address of which it point to.
Java is indeed
pass-by-value but the reference is just actually a fundamental functionalitied