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 ]
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.
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.
posted 15 years ago
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 ]