Does an array object explicitly contain the indexes?

后端 未结 9 2066
时光取名叫无心
时光取名叫无心 2021-02-01 16:18

Since day one of learning Java I\'ve been told by various websites and many teachers that arrays are consecutive memory locations which can store the specified number of data al

9条回答
  •  说谎
    说谎 (楼主)
    2021-02-01 17:05

    The reference of an array is not always on the stack. It could also be stored on the heap if it's a member of a class.

    The array itself can hold either primitive values or references to an object. In any case, the data of an array are always of the same kind. Then the compiler can deal with their location without explicit pointers, only with the value/reference size and an index.

    See:
    * The Java Language Specification, Java SE 8 Edition - Arrays
    * The Java Virtual Machine Specification, Java SE 8 Edition - Reference Types and Values

提交回复
热议问题