如何长Java中的数组实现的? [英] How is length implemented in Java Arrays?

查看:156
本文介绍了如何长Java中的数组实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道的长度 Java数组的实现。我知道,使用 arrayName.length 给我们的元素数量的数组,但不知道是否这是一个方法/函数或者它仅仅是数组的数据成员?

I was wondering about the implementation of length of a Java Array. I know that using arrayName.length gives us the number of elements in the array, but was wondering if this is a method / function or it is just a data member of Array?

我想这一定是一个数据成员,因为我们不使用括号()调用它时,。但是,如果它是一个数据成员如何/时,就是这种价值长度分配/计算的?

I guess it must be a data member as we do not use parenthesis() when invoking it. But if it is a data member how/when is the value of this length assigned/computed?

推荐答案

根据Java语言规范(具体的第10.7节的数组成员的),它是一个域:

According to the Java Language Specification (specifically §10.7 Array Members) it is a field:


      
  • 公共 最后字段长度,其中包含阵列的组件的数量(长度可能是正的或零)。

  •   
  • The public final field length, which contains the number of components of the array (length may be positive or zero).

在内部的值是可能的某处存储在对象头,但是这是一个实现细节,并且依赖于具体的JVM实现

Internally the value is probably stored somewhere in the object header, but that is an implementation detail and depends on the concrete JVM implementation.

的HotSpot虚拟机(一个在流行的Oracle(以前称为Sun)JRE / JDK)店的大小在对象头:在

The HotSpot VM (the one in the popular Oracle (formerly Sun) JRE/JDK) stores the size in the object-header:

[...]数组有第三个标题字段,数组的大小。

[...] arrays have a third header field, for the array size.

这篇关于如何长Java中的数组实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆