• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing arguments

 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic