Of course you can manipulate the object itself when
it's passed by reference!

String is a bad example--it's the exception. String is
immutable and Java creates a new String object behind
the scenes when you try to change it.

This isn't a problem with other objects, such a
StringBugger, er, I mean, StringBuffer. As someone
else has pointed out, StringBuffer allows you to
change the object.

Supposing you have a method:

  static void test(StringBuffer sb)
  {
     sb.delete(0, sb.length());
     sb.append("test");
  }

and a main:

  public static void main(String [] args)   
  {
     StringBuffer sb = new StringBuffer("main");
     test(sb);
     System.out.println(sb);
  }

This will print out "test".

- David Gallardo

--- Tomm Carr <[EMAIL PROTECTED]> wrote:
> In Java, pass by reference works about the same as
> in any other 
> language.  When an object is passed to a method, the
> reference (address) 
> is given to the method.  The method may directly
> manipulate the 
> reference if it desires, but it does not directly
> manipulate the object 
> itself.  


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to