• Post Reply Bookmark Topic Watch Topic
  • New Topic

regarding function call in Java  RSS feed

 
Neha Mohit
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I am a little confuse , let me re-say it "In Java every function call is call by value in case of objects it will be call by value of the reference variables " . Now in the code below swap is working as expected (o/p is JavaRanch), but why does add function is changing the state of the object referenced by aL the o/p should [] rather than [Hi I am ArrayList] .

Please explain , Thanx in advance
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're changing the state of that to which the reference refers (the content of the list).
That's quite possible, as you're not changing the reference itself (you're not replacing the list with another one).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!