Java - 是否可以子类化数组?关于Java中的数组的更多问题 [英] Java - Is it possible to subclass an array? And more questions about arrays in Java

查看:127
本文介绍了Java - 是否可以子类化数组?关于Java中的数组的更多问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些问题纯粹是出于好奇而被问到的。我实际上并不需要子类化数组,我只是想弄清楚它们如何在Java中工作。

These questions are purely asked out of curiosity. I don't actually need to subclass an array, I'm just trying to figure out more about how they work in Java.


  1. 数组的Javadoc API在哪里?我找到了一个'Arrays'类,但该类只包含在Java数组上使用的实用程序,而不是实际的数组类。这引出了我的下一个问题:

  1. Where is the Javadoc API for arrays? I found one for the 'Arrays' class, but that class just contains utilities to use on Java arrays, and is not the actual array class. This leads me to my next question:

是否有一个实际的数组类,其中所有数组都是子类?

IS there an actual array class of which all arrays are subclasses?

Object [] 的超类> [] (例如)?我猜这里的答案是否定的。这些实际的类是否与其他类一样?

Is Object[] a superclass of String[] (for example)? I'm guessing the answer here is no. Are these actual classes like any other class?

String [] 与<$不同的类C $ C>字符串[] [] ?或 String [] [] [] 等?

如标题中所述,是吗?可以子类化一个数组类(或子类数组类?仍然不确定它是如何工作的,你可以通过我上面的问题来判断)?我可以创建自己的类,其实例与数组完全相同,除非它们具有更多功能吗?

As asked in the title, is it possible to subclass an array class (or to subclass THE array class? still not sure how it works as you can tell by my above questioning)? Could I create my own class, instances of which acted exactly like arrays, except they had more functionality?

谢谢。

推荐答案

Java语言规范答案所有这些问题:

The Java Language Specification answers all these questions:


直接超类数组类型是Object。
每个数组类型都实现了Cloneable和java.io.Serializable接口。

The direct superclass of an array type is Object. Every array type implements the interfaces Cloneable and java.io.Serializable.

所以不,所有数组都没有公共基类,因此也没有JavaDoc。数组的成员是已定义由规范代替。

So no, there isn't a common base class for all arrays, and therefore no JavaDoc either. The members of arrays are defined by the spec instead.

数组类型之间的子类型在 4.10.3 - 是的, String [] 对象[] 的子类型。另请参见 ArrayStoreException

Subtyping among array types is defined in section 4.10.3 - and yes, String[] is a subtype of Object[]. See also ArrayStoreException.

是, String [] .class!= String [] [] .class 。 (参见第10.8节

不,没有语法来子类化数组。特别是,扩展条款必须包含类类型(数组类型不是类类型)。

No, there is no syntax to subclass arrays. In particular, the extends clause must contain a class type (and array types are not class types).

这篇关于Java - 是否可以子类化数组?关于Java中的数组的更多问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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