Pavel Avgustinov wrote:
>> import java.util.*;
>>
>> class ArrayTest {
>> public static void main(String args[]) {
>> byte[] row = new byte[10];
>> Vector v = new Vector(10);
>> byte[][] varr = new byte[10][];
>> //jastadd seems to have a problem with n-dim arrays, n>1.
>> v.copyInto(varr);
>>
>> //jastadd compiles 1D arrays fine
>> Vector v2 = new Vector(10);
>> Integer[] v2arr = new Integer[10];
>> v2.copyInto(v2arr);
>> }
>> }
>>
>>
>>
> The signature of copyInto is 'void copyInto(Object[] anArray)'. It seems
> that abc and javac interpret 'byte[]' as a subtype of Object, whence
> 'byte[][]' is a subtype of 'Object[]'. This seems, to say the least,
> counterintuitive to me -- but
> http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html#40879
> suggests Object is indeed meant to be the direct supertype of any array
> type. As such we can boil down the example even further:
>
> public class Test2 {
> public static void main(String[] args) {
> Object[] o = new byte[10][10];
> }
> }
>
> JastAdd then complains that byte[][] isn't assignable to Object[].
> Interestingly, it correctly assigns byte[] to Object.
>
> Actually, this may be a spec ambiguity --
> http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html#40879
> says "The direct superclass of an array type is Object", in other words
> the superclass of byte[][] is Object, not Object[].
>
> Two brief experiments confirm that both javac and jastadd accept 'Object
> o = new byte[2][2];', and javac also accepts 'Object o[] = new
> byte[2][2];'. It's a matter of interpretation of the spec -- but again,
> the de-facto spec is javac, so this should probably be reported as a bug.
>
Actually, I didn't read far enough --
http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html#11430
says " If an array variable /v/ has type /A/|[]|, where /A/ is a
reference type, then /v/ can hold a reference to an instance of any
array type /B/|[]|, provided /B/ can be assigned to /A/.", which seems
to quite clearly indicate that you should be able to assign byte[][] to
Object[], taking A := Object and B := byte[]. Well, if you consider
byte[] a 'reference type', anyway. In other words, this definitely seems
to be a bug.
- P
Received on Fri Jan 13 11:45:19 2006
This archive was generated by hypermail 2.1.8 : Mon Jan 16 2006 - 17:30:09 GMT