double arr[] = {1.5, 2.256, 3.59};
int arr1[] = (int) arr; // compile-error
ok first off, you are trying to cast a double
array to an
int. I think it's a typo right? The "correct" code should be:
double arr[] = {1.5, 2.256, 3.59};
int arr1[] = (
int[]) arr; // compile-error
(that's also the reason why it is better to put the brackets after the type and not after the identifier, int[] arr is better than int arr[])
As for why this is not possible,
JLS 5.5 Casting Conversion makes it very clear:
The detailed rules for compile-time correctness checking of a casting conversion of a value of compile-time reference type S (source) to a compile-time reference type T (target) are as follows:
...
If S is an array type SC[], that is, an array of components of type SC:
...
- If T is an array type TC[], that is, an array of components of type TC, then a compile-time error occurs unless one of the following is true:
- TC and SC are the same primitive type.
...
[ March 19, 2002: Message edited by: Valentin Crettaz ]