How arrays and primitives are passed as parameters in java
Joined: Jul 22, 2005
How arrays and primitives are passed as parameters in java please explain in detail
Joined: Jan 29, 2003
It's important to know all types are passed exactly the same way, by value. That means the JVM makes a copy of the parameter and the called method sees the copy.
If we pass a primitive things are pretty simple. The JVM makes a copy of the primitive and the argument contains the copy. If you change the value of an argument you change the copy, not the original.
When we pass an object the JVM makes a copy of our variable and the method sees the copy. But what is our variable? It's a pointer to an object. So the method gets a copy of the pointer, not a copy of the object.
Does that help?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi