3 ms·
These pedantic discussions are dangerous. The purpose of teaching new programmers value vs reference is to make them aware of the dangers of mutating objects p
by matchagaucho 9y ago
These pedantic discussions are dangerous.
The purpose of teaching new programmers value vs reference is to make them aware of the dangers of mutating objects passed to functions.
public static void main(String[] args) {
MyClass c = new MyClass();
c.Message = "Hello";
c.ID = 1;
mutate(c);
System.out.println(c.Message); // "Goodbye"
System.out.println(c.ID); // 2
}
public void mutate(MyClass c){
c.Message = "Goodbye";
c.ID = 2;
}
public class MyClass{
public String Message;
public Integer ID;
}