r/javahelp • u/djpfg • May 15 '20
how reference variables are passed as method arguments in Java
Hello, I am struggling to understand what this question is asking for, I know in C++ for pass by reference the address of the variable is passed and altered before returning unlike pass-by value(correct me if Im wrong) but in java I thought all values were automatically pass by reference? struggling to make sense of the question so any help at all will be greatly appreciated:)
Explain the difference between how pass-by-reference operates in C++ and how reference variables are passed as method arguments in Java. A good answer will include a simple example of each
16
Upvotes
2
u/random740f May 17 '20
In case anyone stumbles upon this thread in the future:
That is still pass by value... Like I said go back and study your Java fundamentals.
I never said you could not modify the internal fields within the object itself. I said modify the actual memory address. What you are saying is you are an amateur (I actually work in the industry as a professional) who does not understand what "pass by reference" actually means.
Show me how to modify the memory address of a variable in the caller from the called method itself:
https://repl.it/repls/CarefulHideousBusinesssoftware
As I said, you are 100% wrong because that C++ code is impossible in Java.
Clearly everyone in this StackOverflow thread is wrong and you're right:
https://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value/40523#40523
https://www.reddit.com/r/javahelp/comments/9gkzt6/why_does_java_pass_parameters_by_value_instead_of/
Did you even read the OP?
That question would not make sense if pass-by-reference existed in Java.
Nope. Basically you are telling me that you are an amateur and you have no idea what pass by reference actually means.
As I said, I think you are one of those people that can not just admit when they are wrong. :)