Re: arrays and cloning, where is it described?
Andreas Leitgeb wrote:
Mike Schilling <mscottschilling@hotmail.com> wrote:
Daniel Pitts wrote:
Patricia Shanahan wrote:
Andreas Leitgeb wrote:
Why does it say so specifically about arrays of
arrays, but not about arrays of *any* objects?
Is it, because people might otherwise think that
"arrays of arrays" would be more likely to be deep-
cloned than arrays of other objects?
I suspect so. Java pretends just enough multidimensional array
support to be confusing.
I think it also makes a mention because array references are
special.
Even though they can be assigned to an Object reference, they aren't
really an object. The JLS has to be specific about anything that
might be ambiguous otherwise.
But then it is still unspecific about cloning arrays of Objects.
....or I've just still failed to find that mentioned.
In what ways are arrays not objects?
Don't know, if that's what Daniel meant, but arrays are not
accessed through get-/putfield (except for length) or invoke...
opcodes, but through <x>aload/<x>astore opcodes for <x> any
of [abcdfils].
Actually, "length", is not a field on an array "object". To access the
length of an array, you use a specific opcode.
<http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.doc.html>
arraylength
Description
The arrayref must be of type reference and must refer to an array. It is popped from the operand stack. The length of the array it references is determined. That length is pushed onto the operand stack as an int.
The JLS has some strange wording, such as "can be assigned to
variables of types Object, Cloneable, Serializable", instead
of saying that an array *was* all these.
That strange wording is *because* an array is not actually an Object.
Programmers are "tricked" into thinking it is, because it can be
assigned to an Object/Cloneable/Serializable reference.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>