aspose file tools*
The moose likes Java in General and the fly likes passing arguments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "passing arguments" Watch "passing arguments" New topic
Author

passing arguments

Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
I want to pass permitive datatypes by Reference not by value, how can i? I don't want to use any wrapper class. is there any specific operator that accomplish this?


The difference between <b>failure</b> and <b>success</b> is often being <b>right</b> and being <b>exactly right</b>.
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
I want to pass permitive datatypes by Reference not by value, how can i? I don't want to use any wrapper class. is there any specific operator that accomplish this?


Well as far as I know, there is no such operator which can pass primitive as an object reference.

If you don't want to use wrapper classes, then probably you have to write your own class call it Int similar to Integer and use boxing something like below:



You want to achieve something which is not possible at all. Primitves are always passed by value. Even object references are passed by value.

Naseem
[ August 26, 2006: Message edited by: Naseem Khan ]

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Originally posted by Muhammad Ali Amin:
I want to pass permitive datatypes by Reference not by value, how can i? I don't want to use any wrapper class. is there any specific operator that accomplish this?


You don't actually want that since there is an underlying requirement defect in that statement (I won't go into it any further). What you might want (speculation) is some observable change after invocation of some operation with some given data.



Some people do this with "setters" and "getters" (I use those terms to identify with the reader but resent their existence):


You'll note the subtle difference between the two examples. Some would argue that the latter is "more OO". Whatever the case, I think you should be able to solve whatever your problem really is.
[ August 26, 2006: Message edited by: Tony Morris ]

Tony Morris
Java Q&A (FAQ, Trivia)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

Or to put it in cruder terms, passing variables by reference allows you to write methods that have side-effects. This should normally be avoided as it leads to programs that are hard to test and debug.

Is there a reason you think you need that?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: passing arguments