What gets passed to a method is a copy of the reference of the object. So, no matter how many times you re-assign the references, the original reference will not be affected.
Try this:
static void reverse(StringBuilder builder) {
builder.reverse();
}
public static void main(String[] args) {
StringBuilder builder = new StringBuilder("hello");
System.out.println(builder);
reverse(builder);
System.out.println(builder);
}
However, the below method wouldn't make any difference to the original object passed in.
static void swap(StringBuilder builder) {
builder = null;
}