> Hello Newsgroup,
>
[quoted text clipped - 7 lines]
> Why does this work?
> big[0][1] = b1;
The type of big is byte[][][][].
If you write big[x], where x is a number,
the type of that is going to be byte[][][]
(because you've already indexed into one part of this array that you
could think of as multidimensional).
Similarly, the type of big[x][y] (x and y are numbers) is byte[][].
So, when you write:
big[0][1] = b1;
this is allowed because the *type* of the items on both sides is byte[][].
> // or this one
> b2 = b1;
Similarly, the types of b2 and b1 are boths byte[][]. The types match.
Therefore you can do this assignment.
> And why does this not work?
> big[1][2][0] = b2;
The type of the left hand side expression is byte[].
The type of the right hand side is byte[][].
You can't assign these, it doesn't make sense to, and the Java compiler
spots that.
> // or this one
> big[1] = b2;
Type of LHS is byte[][][]; type of RHS is byte[][]. These are not the
matching types.
> Compiler complains in both situations:
> Type mismatch: cannot convert from byte[][] to byte[]
> Type mismatch: cannot convert from byte[][] to byte[][][]
And it was right to complain! Perhaps what you are wanting to do is
manually copy the data from one multidimensional array into the other.
It helps to think of these multidimensional arrays as arrays of arrays.
For example, byte[] is an array of bytes - easy enough.
For byte[][], think of having an array, where each array member is a
byte[] - an array of bytes!
lex
Mike - 06 Jun 2006 17:41 GMT
Hi guys,
Thank you for the answers.
Mike
>> Hello Newsgroup,
>>
[quoted text clipped - 57 lines]
>
> lex
>byte [][] b1 = new byte [10][10];
>byte [][] b2 = new byte [2][1];
[quoted text clipped - 9 lines]
>// or this one
>big[1] = b2;
Think of it this way: Each element of big[] IS a 3-dimension array. Each
element of big[][] IS a 2-dimension array. Each element of big[][][] IS a
1-dimension array. Do the results make sense now?
Lee Weiner
lee AT leeweiner DOT org