The Artima Developer Community
Sponsored Link

Legacy Design Forum
Designing Fields and Methods

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

When to copy parameters?

Posted by Alex Cachia on May 20, 1999 at 10:15 AM

Since all java parameters are passed by reference, when does one
copy the value into the object instead of just using the
reference?

Typically if I have to use the value but not modify it I use the
reference, but if I have to modify the value I'll make a copy.

Is this a good general rule? Also if I provide public get
accessor methods for a class, should I make a copy of the
variable and return the copy or just return the variable?

Thanks,
Cubical programmer #501053



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us