When passing an object as a parameter to a method, for ex. an array, I know that a reference to that object is passed in. If in that method, the formal parameter is made to point to a different object, how come the original variable is still pointing to the same object?
int integers = new int 
calling method changeSize(integers)
public changeSize (int numbers)
int  temp = new int[numbers.length*2];
copying the values of numbers array into temp array;
numbers = temp;
numbers array is pointing to the new array....but integers array is still pointing to the old array.
I heard in C# you can do this, make integers pointing to whatever numbers is pointing at, but in java you can't??? Why is that?
How does C# accomplish this then??
W. Joe Smith
Joined: Feb 10, 2009
In Java you aren't passing the actual reference into the method, rather a copy of the reference. So the numbers reference and the integers reference are 2 seperate references to the same object. If you change the reference in one, it doesn't change the reference in the other.
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."