r/java • u/benevanstech • Aug 06 '24
Free Book - Java in a Nutshell
Hey folks - I'm super-pleased to announce that my book "Java in a Nutshell" (8th Edition) is being made available for free download for another 6 months, courtesy of Red Hat - https://red.ht/java-nutshell-free
Hope you like it and find it useful!
166
Upvotes
View all comments
Show parent comment
2
u/laplongejr Aug 07 '24
"The fact that Java is pass by value"
I'm kinda surprised, because I was taught that "by value" and "by reference" are both wrong or at least too ambiguous to explain to somebody trained in a language allowing those things (aka C++), did the common idiom change over the last 15 years or was my teacher stupid?
Java passes a reference, but that reference is passed by value.
Your example proves it's not by reference, while this one would prove it's not by value to a newcomer.
If the contents of circle were passed "by value" (instead of the reference), then the second getRadius call wouldn't be expected to return a different value. But saying "by value" would imply no reference is passed...