I have four helper methods. void inc(int n) { n++; } has no effect on the caller's variable. void add(List<Integer> list) { list.add(5); } does change the caller's list. But void reset(List<Integer> list) { list = new ArrayList<>(); } leaves the caller's list untouched, and void shout(String s) { s = s.toUpperCase(); } does nothing either.
My textbook says primitives are passed by value and objects by reference, but that does not explain the third and fourth cases. What is the actual rule, and how do I write a method that gives back more than one result?




