Angus Comber wrote:
Jeff Verdegan wrote:Again, remember, we're not passing the array, we're passing a reference to the array. You can't pass a reference to part of an array any more than you can pass a reference to part of any other object.
The fact that it is a reference I don't think is the issue. What is a reference? Just an alias for the actual object.
No, it's not an alias, and the fact that it's a reference to an object is precisely the issue. The reference is a pointer to the object. If you're familiar with C++, a Java reference is much more like a C/C++ pointer than a C++ reference. A C++ reference is often referred to as an alias for a variable, but Java's references are nothing like that.
In some languages you can specify an offset to an array.
Not in Java. In java a reference to an array is just like a reference to any other object, and a reference to an array is
not simply a pointer to its first element.
But the Java 'array' is not really a section of memory like say an array in C, it is a class (I suppose).
Correct. It's probably implemented that way in the JVM, but it's not specified as such in the JLS, so Java programmers have no visibility into that bit.
So the start of the Java array is the start memory location of the object, not the direct location in memory of the first element.
Not even that. There is no "start" of the array, just a reference to it, and I think you'll find that the JLS doesn't define references in terms of memory locations.