Re: Passing Primitive Types "By Reference" In Java

  • From: Jared Wright <wright.jaredm@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Mon, 04 Feb 2008 07:42:44 -0500

Sina Bahram wrote:
"What is it that you're trying to do?"
Nothing good, it seems. *grin* Basically, the context is roughly that of a calendar. I wanted to call the tomorrow method, increment the two aspects that get incremented every day (day of week and the day of the month), then call a separate method to put the new date through all the appropriate checks and fix any inaccuracies (roll over the month, roll over the week, deal with February and Leepear, etc.). Since I sent that out I realized I could just declare all the needed variables as private data members "globally" in the class itself and not actually call the method with any specific parameters. I just called the tomorrow method, then the validation method with no parameters, but since all the parameters I'd be working with were declared just within the context of the class, the method that validated the accuracy of the date was able to check and change them all as necessary. This way I could manipulate all the integers in the MyDate class. Not sure how wise a solution that is, but it seems to have kept me moving in the meantime.

The program itself is a project for class, aimed at working on the implementation side of inheritance. The prof has admitted that programatically it's not the way one would normally lay things out, but as mentioned, he's trying to force us into a particular arena, so to speak. If you want to see the whole story, I'd be happy to fill you in, but I don't know if the list wants me to push that amount of code on everyone's inbox. *grin* I do get though that my approach in this situation of trying to essentially pass a primitive by reference was probably not the smartest way to go. Hopefully this new wrinkle will continue to be sufficient.

Jared
__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: