Re: method call on result of method call
patrol wrote:
From Wikipedia: Reference(Computer Science)
"A reference is distinct from the data itself. Typically, a reference
is the physical address of where the data is stored in memory or in
the storage device. For this reason, a reference is often called a
pointer or address, and is said to point to the data."
This seems to be saying that a reference *is* synonymous with a
pointer. They both refer/point to the memory address where the data is
located. No?
Eric Sosman wrote:
No. A reference is any kind of datum that allows you to
locate some other datum, the thing the reference refers to.
One particularly efficient type of reference, suitable for use
in a computer's memory, is an address. But that's by no means
the only possible kind of reference, nor the only kind used!
Everything you say is true, but this conversation is primarily about
references in Java, as defined by the JLS. While the Wikipedia entry
and your comments apply to the wide universe, it isn't the only
example where the usage in the context of Java is much more narrowly
and idiosyncratically defined.
In Java, a reference is a pointer. It is not precisely accurate to
say that the reference or pointer is a memory address, first because
in Java there is no such thing as a memory address per se, and second
because even in the JVM addresses mutate in the face of GC.
The relevant understanding for Java is that a reference points to the
instance, or you could say a pointer references the instance. The
mechanism for how it points to the instance, be it via memory
addresses or hops through a series of lookup tables (LUTs) or
incantations to ancient Aztec deities, is not important. On the left
you have a pointer (variable or what-have-you), on the right you have
the instance to which it points. (Southpaws, switch left for right
and vice versa.)
Even outside of Java the exact mechanism of, say, a C pointer depends
on the platform. We conceptualize pointers as integers that locate a
specific spot in memory, but under the hood the host system may go
through various translations and lookups to get at the "real"
address. For all we care, that, too, might involve incantations to
ancient Aztec deities.
The definition is in the JLS. The JLS gets to define terms within the
specific domain of discourse of Java language syntax and semantics.
There's really nothing else to say on the matter within that domain of
discourse.
--
Lew