• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passed by reference or by value?

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having some trouble figuring out whether the following GridBagConstraints c is being passed by reference or value to a method: It's really important that it be passed by reference, which is how I understood Java works...


In other words, when the method initGridBagConstraints is called, will it re-initialize origC as well as passedC?

[ July 18, 2004: Message edited by: Ryan Smith ]
[ July 18, 2004: Message edited by: Ryan Smith ]
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You aren't going to do what you're trying. There are all kinds of discussions about Java and pass by value and pass by reference. The easy thing to remember is that you can modify an object by calling methods on it. You can never reassign an object that was passed into a method. For example -



The above will infact change the name to Sam. If instead you did this -


You won't get the name change, as you can't modify where myObj points to from within a method. Technically, java is always pass by value.

Here's some more insight -

http://www.javaranch.com/campfire/StoryPassBy.jsp

HTH,
Aaron R>

PS - If you aren't going to do anything else in your init method, then you should just do a new wherever you would have called that method.
 
Ryan Smith
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Woohoo!!! I'm done!!! YAY!!! Thanks! And thank you very much for the informative value vs. reference explanation - the book I'm using doesn't explain beyond a simple definition.
[ July 18, 2004: Message edited by: Ryan Smith ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic