Recap of References
- Java does not support explicit pointers like C++.
- Everything in Java is a reference, except primitives.
- Assignment and argument passing for non-primitives is done using
references.
- Internally, a reference is like a pointer, except that the programmer
does not have to dereference it or deal with pointer arithmetic because
Java does this automatically.
- Two important points to remember related to references:
- If you want two objects to actually be separate objects that have the
same values, use new. If you do not, changing a value
in one object will also change the value in the other since they will
point to the same object in memory.
- Non-primitive arguments are
pass by reference
so if an argument is changed in a method, the object's value is really
changed, even after the method returns.