Java

Repeat after me: Java is pass-by-value


Although I have blogged previously about “Java Pass by value” the JavaRanch Campfire story here is probably the best explanation of it I have seen so far. The ‘remote control’ analogy for object references makes it much easier to understand for any newbie.

The reinforcement at the end of the story is pretty cool and sums everything up nicely… 🙂

So repeat after me:
Java is pass-by-value.
(OK, once again… with feeling.)
Java is pass-by-value.
For primitives, you pass a copy of the actual value.
For references to objects, you pass a copy of the reference (the remote control).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s