Hi guys,

I found this thread (http://www.daniweb.com/forums/thread19814.html) that gave me guidance on this topic but I wanted to further develop my understanding.

I understand that in Java, everything 'passes by value', even references. That is, a copy of the value is passed to the parameter so the original value is left unchanged.

In the cases of when Java "passes-by-reference" it is still passing by value as its passing the value of a copy of the reference to the object for example: a balloon analogy:

Balloon = object
String connected to the balloon = reference

So when "passing-by-reference", what's happening is that a copy of the reference to the original object is being passed enabling the original value to be modified? In keeping with the balloon analogy, would it be correct to say that the object (the balloon) now has 2 references (strings) attached to it, that is, the original reference and the copied reference being passed?

Thanks.

Recommended Answers

All 3 Replies

Thanks for the links, makes sense now.

... would it be correct to say that the object (the balloon) now has 2 references (strings) attached to it, that is, the original reference and the copied reference being passed?

Yes

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.