Chapter 10. Arrays
要明白elementtype与componenttype
There are some situations in which an element of an array can be an array: if the element type is Object
or Cloneable
or java.io.Serializable
, then some or all of the elements may be arrays, because any array object can be assigned to any variable of these types.
If an array variable v
has type A[]
, where A is a reference type, then v
can hold a reference to an instance of any array type B[]
, provided B can be assigned to A (§5.2). This may result in a run-time exception on a later assignment; see §10.5 for a discussion.
Arrays must be indexed by int
values; short
, byte
, or char
values may also be used as index values because they are subjected to unary numeric promotion (§5.6.1) and become int
values.
An attempt to access an array component with a long
index value results in a compile-time error.