如何数组在Java中实现? [英] How are arrays implemented in java?

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

问题描述

数组实现为正确的Java对象?如果是这样,我在哪里可以查看源$ C ​​$ C Array类。我想知道如果在阵列中的长变量定义为一个常数,如果是这样,为什么它不是在所有的大写字母长度,使code更容易理解。

Arrays are implemented as objects in java right? If so, where could I look at the source code for the array class. I am wondering if the length variable in arrays is defined as a constant and if so why it isn't in all capital letters LENGTH to make the code more understandable.

推荐答案

尽管阵列在这个意义上,他们继承的java.lang.Object对象,动态创建的类作为语言的特殊功能。他们不是在源$ C ​​$ C定义。

Although arrays are Objects in the sense that they inherit java.lang.Object, the classes are created dynamically as a special feature of the language. They are not defined in source code.

考虑这个数组:

   MySpecialCustomObject[] array;

有没有源$ C ​​$ C表示。您在code动态创建它。

There is no source code for that. You created it in code dynamically.

之所以长度在小写和场实际上是关于一个事实,即后来的Java编码标准没有在此被开发的时间存在。如果一个数组目前正在开发中,它很可能是一个方法:的getLength()

The reason why length is in lower case and a field is really about the fact that the later Java coding standards didn't exist at the time this was developed. If an array was being developed today, it would probably be a method: getLength().

长度是在对象结构所限定的最后字段,它不是恒定的,所以一些编码标准将不希望这样的大写。然而,在一般的Java中一切的今天,一般无论是作为一个常量做大写或标记为私人与公共getter方法​​,哪怕是最后的。

Length is a final field defined at object construction, it isn't a constant, so some coding standards would not want that to be in upper case. However in general in Java today everything is generally either done as a constant in upper case or marked private with a public getter method, even if it is final.

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

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