• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing a Primitive By reference

 
Whiz Kid
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks in advance for your replies
I dont clearly Follow how to pass a primitve data type by reference ?Can anyone explain this to me?
Thanks
Gowri
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java, everything is passed by value. Primitives are copied and passed on to the method and references are copied also but they still reference the same object on the heap.
If you want to pass a primitive by reference, the only I know of is to wrap it in an array and pass the array to the method. For instance,
 
Whiz Kid
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much.
have a good day
 
Paul Villangca
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Valentin,
I'm surprised the name 'Whiz Kid' is acceptable with the naming policy and all.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not
I've already sent him an email and dropped my comments in two of his recent posts... I didn't want to spoil all threads with naming policy enforcement messages.
 
Paul Villangca
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry 'bout that Valentin, I'm just used to seeing the naming policy response in all the threads posted by weird names.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem Paul, just don't hesitate to let me know, usually I look at all posts but some may slip through
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Val:
The following code:

Should it not be:

This code also provide same result as yours but
it proves the point you are trying to make. Or
am I off-the-base here?
Thanks
Barkat
[ August 18, 2002: Message edited by: Barkat Mardhani ]
[ August 18, 2002: Message edited by: Barkat Mardhani ]
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right Barkat. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic