在Java中,为什么是数组对象?是否有任何特殊的理由? [英] In Java, why are arrays objects? Are there any specific reasons?

查看:247
本文介绍了在Java中,为什么是数组对象?是否有任何特殊的理由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何理由,Java中的数组是一个对象?

Is there any reason why an array in Java is an object?

推荐答案

由于Java语言规范的是这样说的 :)

Because the Java Language Specification says so :)

在Java编程语言数组是(第4.3.1节),动态创建的对象,并且可以被分配给Object类型的变量(§4.3.2)。 Object类的所有方法都可以在阵列上被调用。

In the Java programming language arrays are objects (§4.3.1), are dynamically created, and may be assigned to variables of type Object (§4.3.2). All methods of class Object may be invoked on an array.

所以,不像C ++,Java提供了真正的数组作为第一类对象:

So, unlike C++, Java provides true arrays as first-class objects:


  • 有一个长度成员。

  • 有一个的clone()它覆盖类的同名方法方法对象

  • 加类的所有成员对象

  • 一个例外是如果您试图访问数组越界异常。

  • 数组实例化的动态内存。

  • There is a length member.
  • There is a clone() method which overrides the method of the same name in class Object.
  • Plus all the members of the class Object.
  • An exception is thrown if you attempt to access an array out of bounds.
  • Arrays are instanciated in dynamic memory.

这篇关于在Java中,为什么是数组对象?是否有任何特殊的理由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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