[47] in java-interest

home help back first fref pref prev next nref lref last post

Semantics of parameter passing

daemon@ATHENA.MIT.EDU (Richard Tuck)
Thu May 4 17:08:30 1995

Date: Thu, 4 May 1995 13:52:57 +0800
From: rt@scndprsn.Eng.Sun.COM (Richard Tuck)
To: java-interest@java.Eng.Sun.COM

James -

Thank you for pointing out this omission in the language
spec. As you have discovered, scalars are all passed by value.
Variables of class and array types are, of course, references
to objects, and these variables are passed by value, too. So
what the invoked method sees is a reference to an object, >not<
a reference to the variable referencing the object. Here's a
simple example.
	
static void changearray( int v[] ){
    v[0] = -1;
    v = new int[3];
    v[0] = -2;
    v[1] = -3;
    v[2] = -4;
}
...
    int a[] = { 0, 1, 2, 3, 4, 5, 6 };
    changearray( a );
What this calling code sees as the value of array a after the call to
changearray is { -1 1 2 3 4 5 6}, rather than the new array allocated
in changearray. We'll try to make this more clear in future.

Thanks also for pointing out the murky wording on page 6. We will
certainly look at cleaning this up as you propose.

		Richard Tuck
		

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post