Wednesday, 9 May 2018

Passing a String by Reference in Java?

I am used to doing the following in C:



void main() {
String zText = "";
fillString(zText);
printf(zText);
}


void fillString(String zText) {
zText += "foo";
}


And the output is:



foo



However, in Java, this does not seem to work. I assume because the String object is copied instead of passed by referenced. I thought Strings were objects, which are always passed by reference.



What is going on here?

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...