• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

regarding function call in Java

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
reply
    Bookmark Topic Watch Topic
  • New Topic