0

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.

Mogsdad
  • 42,835
  • 20
  • 145
  • 262
Johnny Beltran
  • 541
  • 6
  • 16

1 Answers1

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,148
  • 2
  • 86
  • 88