[1797] in java-interest
Re: A few queries...
daemon@ATHENA.MIT.EDU (Andrew Wason)
Sun Sep 17 01:01:32 1995
To: java-interest@java.sun.com
In-Reply-To: Message from Llew Mason <mason_l@ee.uwa.edu.au>
of "Fri, 15 Sep 95 21:35:04." <01BA83B3.200B3520@s158.dialup.uwa.edu.au>
Date: Fri, 15 Sep 95 15:00:27 -0400
From: Andrew Wason <aw@bae.bellcore.com>
Llew Mason <mason_l@ee.uwa.edu.au> writes:
>
> As far as I could tell this wasn't discussed in any of the provided =
> documention. Java currently passes class arguments by non-const =
> reference.
It looks like method arguments are passed by value.
The following prints:
o=java/lang/Object[]i=10
o=java/lang/Object[]i=10
If the arguments were passed by reference, the locals in main()
would have been modified by the call to foo.
class Ref {
static void foo(int i, Object o) {
i = 7;
o = new Object();
}
public static void main(String argv[]) {
int i = 10;
Object o = new Object();
System.out.println("o=" + o + "i=" + i);
foo(i, o);
System.out.println("o=" + o + "i=" + i);
}
}
Andrew
_______________________________________________________________________________
Andrew Wason Bell Communications Research
aw@bae.bellcore.com Piscataway, NJ
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com