I know there have been several posts explaining argument passing in Java. I also know that the arguments are passed by value but the value is the reference to the object. Say I have the following 2 mthods.
public void append(List<String> list){
list.add("some string");
}
public void incr(int count){
count++;
}
If I call the first method, the object list
gets modified and the modified value exists after the method call too. But when I call incr(count)
, the modified value of count
is lost once the method call returns.
Why is it that in some cases, the value gets modified but in the other it does not?