[EMAIL PROTECTED] wrote:
>
> I expected the following to work since Objects are supposedly
> pass-by-reference. Am I doing something wrong here?
>
> I'm just trying to change a Boolean value inside of a method and return
> as pass-by-reference to the caller.
>
> My environment is:
> Blackdown JDK1.2 pre2, RedHat 6.1, glibc 2.1.2
>
> The output of the following program is:
> Boolean before: false
> changeBoolean(): false
> changeBoolean(): true
> Boolean after: false
>
> I expected the Boolean after: to be true.
>
two rules:
primitives are passed by value.
objects are passed by reference
solution pass an array which qualified as an object since you
must `new ...' it!!!
> ----------------------------------------------------------------------
> public class BooleanTest2 {
public void changeBoolean(Boolean [] pbj ) {
>
> System.out.println("changeBoolean(): " + b.booleanValue());
> b = Boolean.TRUE;
> System.out.println("changeBoolean(): " + b.booleanValue());
obj[0] = Boolean.True;
> }
>
> public static void main(String args[])
> {
> BooleanTest2 bt = new BooleanTest2();
> Boolean bool = new Boolean(false);
>
> System.out.println("Boolean before: " + bool.booleanValue());
Boolean [] obj = new Boolean [1];
obj[0] = Boolean.False;
s.o.println( "before:"+obj[0] );
bt.changeBoolean( obj);
s.o.println( "after:"+obj[0] );
> System.out.println("Boolean after: " + bool.booleanValue());
> }
> }
>
> -----------------------------------------------------------------------
> I expected the following to work since Objects are supposedly
> pass-by-reference. Am I doing something wrong here?
>
> I'm just trying to change a Boolean value inside of a method and return as
> pass-by-reference to the caller.
>
> My environment is:
> Blackdown JDK1.2 pre2, RedHat 6.1, glibc 2.1.2
>
> The output of the following program is:
> Boolean before: false
> changeBoolean(): false
> changeBoolean(): true
> Boolean after: false
>
> I expected the Boolean after: to be true.
>
> ----------------------------------------------------------------------
> public class BooleanTest2 {
> public void changeBoolean(Boolean b) {
>
> System.out.println("changeBoolean(): " + b.booleanValue());
> b = Boolean.TRUE;
> System.out.println("changeBoolean(): " + b.booleanValue());
> }
>
> public static void main(String args[])
> {
> BooleanTest2 bt = new BooleanTest2();
> Boolean bool = new Boolean(false);
>
> System.out.println("Boolean before: " + bool.booleanValue());
> bt.changeBoolean(bool);
> System.out.println("Boolean after: " + bool.booleanValue());
> }
> }
--
Adios
Peter
-----------------------------------------------------------------
import std.Disclaimer; // More Java for your Lava, Mate.
"Give the man, what he wants. £££" [on Roy Keane, Quality Player]
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]