I was kind of baffled when I saw the following code did not work as expected.
I thought Java always passed variables by references into functions. Therefore, why the function assign the variable?
public static void main(String[] args) {
String nullTest = null;
setNotNull(nullTest);
System.out.println(nullTest);
}
private static void setNotNull(String s) {
s = "not null!";
}
outputs "null"