Array types confusion
The thread that was deleted addressed what's probably a common source of confusion. To that end, here are the highlights:
class P{}
class Cextends P{}
P[] arr =new C[1];
arr[0] =new P();// compiles, but ArrayStoreException at runtime
C extends P, but C[] doesnot extend P[]. Arrays extend Object.
[url http://java.sun.com/docs/books/jls/third_edition/html/arrays.html#10.8]JLS 10.8 Class Objects for Arrays[/url].
It compiles because when doing the assignment into arr[0], the compiler only knows that arr is an array of P and that new P() produces a P. The compiler doesn't know that arr happens to point to a C[].
You get the exception because the array object you have is a C[], and you can't put a P into a C[] becase a P is not a C.
[1115 byte] By [
jverda] at [2007-10-2 11:03:44]

> [url http://java.sun.com/docs/books/jls/third_edition/html/arrays.html#10.8]JLS 10.8 Class Objects for Arrays[/url].
And if you scroll down a bit from there, you'll find almost exactly the same thing as what I was saying, in [url http://java.sun.com/docs/books/jls/third_edition/html/arrays.html#10.10]10.10[/url]
<cite>
P[] arr = new C[1];
arr[0] = new P(); // compiles, but ArrayStoreException at runtime
C extends P, but C[] does not extend P[]. Arrays extend Object.
</cite>
What do you exaclty mean by saying "C[] does not extend P[]" ?
There is no place to explicitly declare an inheritance relationship between the two array types. But this line's getting compiled
P[] arr = new C[1];
shows that P[] is assignable from C[].
Class.getSuperclass() returns Object.class for an array type indeed.