Java Reference
In-Depth Information
An array's length is not part of its type.
The element type of an array may be any type, whether primitive or reference. In particular:
• Arrays with an interface type as the element type are allowed.
An element of such an array may have as its value a null reference or an instance
of any type that implements the interface.
• Arrays with an abstract class type as the element type are allowed.
An element of such an array may have as its value a null reference or an instance
of any subclass of the abstract class that is not itself abstract .
The supertypes of an array type are specified in § 4.10.3 .
The direct superclass of an array type is Object .
Every array type implements the interfaces Cloneable and java.io.Serializable .
10.2. Array Variables
A variable of array type holds a reference to an object. Declaring a variable of array type
does not create an array object or allocate any space for array components. It creates only
the variable itself, which can contain a reference to an array.
However, the initializer part of a declarator (§ 8.3 , § 9.3 , § 14.4.1 ) may create an array, a ref-
erence to which then becomes the initial value of the variable.
Example 10.2-1. Declarations of Array Variables
Click here to view code image
int[] ai; // array of int
short[][] as; // array of array of short
short s, // scalar short
aas[][]; // array of array of short
Object[] ao, // array of Object
otherAo; // array of Object
Collection<?>[] ca; // array of Collection of unknown type
The declarations above do not create array objects. The following are examples of de-
clarations of array variables that do create array objects:
Click here to view code image
Exception ae[] = new Exception[3];
Object aao[][] = new Exception[2][3];
Search WWH ::




Custom Search