In C++ I might do something like:
sometype var = somevalue;
mutate(var);
// var is now someothervalue
void mutate(sometype &a) {
a = someothervalue;
}
Is there an equivalent thing in Java?
I am trying to accomplish something like:
Customer a;
public static void main(String[] args) {
a = newCustomer("Charles");
Customer b = null;
mutate(b);
System.out.println(b.getName()); // NullPointerException, expected "Charles"
}
void mutate(Customer c) {
c = a;
}
If Customer
is mutable, why does this yield NullPointerException?