数组成员(数组理论Java)

Array Members (Theory about Arrays Java)

在 java 学习数组时,我想到了这篇文章:

10.7。数组成员 数组类型的成员如下: public 最终字段长度,其中包含数组的组件数。长度可以是正数或零。 public 方法克隆,它覆盖了 class 对象中的同名方法并且不抛出已检查的异常。数组类型T[]的clone方法的return类型为T[]。 多维数组的克隆是浅表的,也就是说它只创建一个新数组。子数组是共享的。 所有成员继承自 class 对象; Object 唯一不被继承的方法是它的 clone 方法。

谁能给我解释一下这是什么意思?

10.7. Array Members The members of an array type are all of the following:

这是您可以对数组类型调用的内容。

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

您可以调用 array.length,它会如您所愿。

The public method clone, which overrides the method of the same name in class Object and throws no checked exceptions. The return type of the clone method of an array type T[] is T[]. A clone of a multidimensional array is shallow, which is to say that it creates only a single new array. Subarrays are shared. All the members inherited from class Object; the only method of Object that is not inherited is its clone method.

您可以调用 array.clone(),这将 return 数组的浅表副本。您可以在此处了解有关浅拷贝与深拷贝的更多信息:What is the difference between a deep copy and a shallow copy?

我不会把这段话称为理论。这解释了您可以在数组变量上使用的成员字段和方法。它非常具体和实用。克里斯在另一个答案中很好地解释了细节。我建议你多了解 类、成员字段和方法。学习 类 和对象的基本术语将帮助您理解其含义。