3 ms·
Why is it inaccurate to call it a reference in Java? You don't dereference a variable in Java to access it, so that would make me think reference, not pointer.
by wspeirs 12y ago
Why is it inaccurate to call it a reference in Java?
You don't dereference a variable in Java to access it, so that would make me think reference, not pointer.
- jjnoakes 12y agoBy you do deference object variables in Java. What do you think the "." operator does?
- wspeirs 12y agoAh, true... so what is the difference between a reference and a pointer then?
- jjnoakes 12y agoIt depends on which definition of "reference" you are talking about. Pass-by-reference and C++ references are basically the same - aliasing without requiring dereferencing via an operator. Java object references are like C++ pointers. Java is pass-by-value (no aliasing) for all values (ints, bools, object references etc). Java has no object values.
- cbr 12y ago'a.b()' dereferences 'a' to call its 'b' method. If 'a' is null you'll get a NullPointerException.
- sixbrx 12y agoAlternatively, the NullPointerException could be viewed as a simple leakage of implementation details, which is a common issue with exceptions.