Saturday, January 15, 2011

Java is PASS BY VALUE. -

If you pass a primitive to a method, you don't get a reference to that primitive; you can't change it in that method. Pass by value.

If you pass an object reference, including an array, to a method, then the reference value is copied. Pass by value. Since the copied reference value is the same as the reference value that it was copied from, you can modify the state of the referenced object, but you can't alter the original reference in the method.

Get it right: you can modify the referenced object's state, but you can't modify the reference itself.

This is not because of magic elfs that defend the reference with life and limb. This is because Java is pass by value."

1 comment: