, "". , , . , , :
public void foo() {
String s = "example";
String param = s;
bar(param);
assert s == param : "The value of parameter reference was not modified";
assert param.equals("example");
}
public void bar(String param) {
param = "something different";
}
, , , . :
public void foo() {
List<String> l = Arrays.asList("example");
List<String> param = l;
bar(param);
assert s == param : "The value of parameter reference was not modified";
assert !param.get(0).equals("example") : "bar changed the internal state of the parameter";
assert !l.get(0).equals("example") : "bar changed the internal state of the list that is reference equal to the parameter";
}
public void bar(List<String> param) {
param.set(0, "something different");
}
, , . . Java java.lang.Object java.lang.String , . Java , , , JavaDoc / , , .