I have seen some examples of getting the length of an array using the field length, for example: array.length. I have always used this field but checking the array documentation I did not see that variable. Why is it that the documentation doesn't show it? It only shows a bunch of methods but I can't see the variable length. Is it in another class or what? I have seen questions like this before but the answers are not well explained so I can't understand them.
Asked
Active
Viewed 96 times
0
-
1Which array documentation are you referring to? – Dave Newton May 23 '15 at 17:16
-
http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Array.html – Johnny Beltran May 23 '15 at 17:31
-
That's a class to manipulate arrays, just like its docs say. – Dave Newton May 23 '15 at 17:33
-
Then there isn't a class that shows what actually an array is and all of its members and methods? – Johnny Beltran May 23 '15 at 17:40
-
2No, and class `java.lang.reflect.Array` is not the actual class of arrays. – Jesper May 23 '15 at 17:51
1 Answers
1
Because length is not actually a field. The compiler recognizes the identifier specially and translates it to an arraylength
instruction rather than a getfield
instruction.

Brett Kail
- 33,593
- 2
- 85
- 90