Each parameter of the function passed by value - however, the parameter is not an object, but instead is a link.
So, the same object exists with two references to it.
String s = "my string"; // reference to this object created doSomething(s); // in the doSomething function, a new reference to the same point of memory is passed by value
This means that when I have my void doSomething(String str) function, I work the same way as outside the function, except that I have another link. The same object referenced, but with a different link. Therefore, if inside my function I do str = "different string"; , which will not change, ss still points to the same memory point as all this time, but now str instead of indicating that points to points, now indicates where the "different line" is stored.
corsiKa
source share