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
  • 44,709
  • 21
  • 151
  • 275
Johnny Beltran
  • 701
  • 2
  • 8
  • 22

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,593
  • 2
  • 85
  • 90