| Author |
Passing arguments
|
Mike Lipay
Ranch Hand
Joined: Sep 11, 2007
Posts: 171
|
|
I'm having a problem with passing arguments, and I figure it's something really stupid that I'm doing wrong. The arguments are going into the routine right, but the routine is suppose to modify them and return the modified values back. What's coming back is the original values.
|
 |
Bill Shirley
Ranch Hand
Joined: Nov 08, 2007
Posts: 457
|
|
Java is pass by value. If you find yourself passing two values to a function, and wanting to return the two values, those values prob'ly belong in their own class. And indeed there is a Date class in java you can use. I suggest the new method take the Date instance, create a new Date instance with the new value, and return that. [edit: Date not Data, fixed typo] [ February 08, 2008: Message edited by: Bill Shirley ]
|
Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9948
|
|
When you pass something into a method, you basically make a copy of it. in your case, you'll have a datePascha from the main method, then inside your getDateOfPacha method, you create a second variable called dateOfPascha, and you give it the same value. When you change dateOfPascha inside your method, that does nothing to datePascha outside of your method.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Mike Lipay
Ranch Hand
Joined: Sep 11, 2007
Posts: 171
|
|
Bill, Thanks. From the article I cheated, passing an array in and out, then reassigning the array to a scalar. Not the best method, but quick and works. Do you have a link to something that would explain the Data Class? Thanks, Mike
|
 |
Bill Shirley
Ranch Hand
Joined: Nov 08, 2007
Posts: 457
|
|
The API docs on the Date class are pretty good. Also, Calendar may be of some use.
|
 |
Mike Lipay
Ranch Hand
Joined: Sep 11, 2007
Posts: 171
|
|
Originally posted by Bill Shirley: If you find yourself passing two values to a function, and wanting to return the two values, those values prob'ly belong in their own class. And indeed there is a Data class in java you can use.
Bill, you mentioned a "Data class", that is what I was asking about, not the Date routines. Do you have a link to something about the Data class?
|
 |
Bill Shirley
Ranch Hand
Joined: Nov 08, 2007
Posts: 457
|
|
Originally posted by Mike Lipay: Bill, you mentioned a "Data class"... class?
Sorry, typo Data -> Date
|
 |
 |
|
|
subject: Passing arguments
|
|
|