Java Reference
In-Depth Information
System.out.println(e);
}
}
}
}
This program produces the output:
1
2
before causing a NullPointerException in trying to index the second component of the ar-
ray ia , which is a null reference.
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.
• The public method clone , which overrides the method of the same name in class Ob-
ject and throws no checked exceptions. The return type of the clone method of an ar-
ray 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.
An array thus has the same public fields and methods as the following class:
Click here to view code image
class A<T> implements Cloneable, java.io.Serializable {
public final int length = X ;
public T[] clone() {
try {
return (T[])super.clone(); // unchecked warning
} catch (CloneNotSupportedException e) {
throw new InternalError(e.getMessage());
}
}
}
Note that the cast in the example above would generate an unchecked warning
5.1.9 ) if arrays were really implemented this way.
Search WWH ::




Custom Search