| Author |
How arrays and primitives are passed as parameters in java
|
Mintoo Jaiswal
Greenhorn
Joined: Jul 22, 2005
Posts: 8
|
|
|
How arrays and primitives are passed as parameters in java please explain in detail
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
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
|
 |
Mr. C Lamont Gilbert
Ranch Hand
Joined: Oct 05, 2001
Posts: 1170
|
|
|
Its got to be in the FAQ by now.
|
 |
 |
|
|
subject: How arrays and primitives are passed as parameters in java
|
|
|