Search this site:

2008-01-23

Java: pass by reference or value?


Does Java pass function arguments by reference or value?

This is a confusing question. There are tons of people arguing this on the web. Here is my comment:

  • Java passes function arguments by value
  • Java handles object with object reference
So, when Java passes objects into function, it actually passes the object references. Object references is nothing special to other types, they are passed into function by values. That is, in short, Java passes object reference by value.

If you want to know more, read this very good article explaining the problem clearly with codes and graphical examples.


No comments:

Post a Comment

HTML Tags allowed (e.g. <b>, <i>, <a>)

Disclaimer

ALL CONTENTS AND INFORMATION IN THIS WEB SITE ARE PROVIDED "AS IT" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE ACCURACY AND AVAILABILITY OF THE CONTENTS, INFORMATION AND THE WEB SITE ITSELF ARE NOT GUARANTEED. THE AUTHOR TAKES NO RESPONSIBILITIES ON ANY COSTS OR DAMAGES (DIRECT OR INDIRECT) ARISING OUT OF OR IN CONNECTION WITH THE ACCESS, USAGE OR INABILITY OF USAGE OF THIS WEB SITE.