Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing arguments

 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The API docs on the Date class are pretty good.

Also, Calendar may be of some use.
 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Lipay:
Bill, you mentioned a "Data class"... class?


Sorry, typo

Data -> Date
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic