On Sat, 17 Jul 2010 23:35:39 -0700, Mike Schilling wrote:
"ClassCastException" <zjkg3d9gj56@gmail.invalid> wrote in message
news:i1tto7$f8o$2@news.eternal-september.org...
On Sat, 17 Jul 2010 11:21:26 -0700, Mike Schilling wrote:
Or, to paraphrase everyone else who's answered this question, Java
does not have aliasing of references.
Not quite. It comes close, though, with the right constructs: reference
a points to object 0, which has an instance field b that points to
object 1. a.b = null changes the latter. In a sense, reference b is
aliased if we have a reference c that also points to object 0 so c.b ==
null now as well.
My point was that there's no Java construct that's a reference to a
reference [1], but you're quite right that there are references to
objects that contain references.
1. That is, nothing like the C++
char *p;
char * &q = p;
That is to say, a reference in and of itself can't be treated as a first-
class object. You can explicitly encapsulate it in one (and the
java.lang.reference classes do so, with almost-immutable ones that the GC
can set to null).
Similarly to how Java lacks first-class functions but allows a one-method
interface like Comparator or ActionListener whose implementations'
instances can be passed around for similar purposes.
Yup. Java has one hammer and thus everything is a nail.