Page 1 of 1

[HD Pg 108, Sec. 4.3.2 - assigning-arrays-of-primitives-to-object-variables]

Posted: Wed Jul 21, 2021 8:48 am
by enthunoob
Very good point made here. Every array is an object. With the example given:

Object[] oa = new int[2][3]; //this is valid.
Object[][] oaa = new int[2][3]; //this will not compile.

It means that the last line would compile if it had a set of braces behind it:
Object[][] oaa = new int[2][3][1]; //this should compile.

Besides that, it also means that the (level of) dimensions do not have to be specified left of the assignment character, right? Cause array or not, it's an object (that on coincidence is an object holding references to other objects). So this would also compile:

Object oa = new int[2][3]; //this should also compile (?)

Re: [HD Pg 108, Sec. 4.3.2 - assigning-arrays-of-primitives-to-object-variables]

Posted: Wed Jul 21, 2021 10:07 am
by admin
What happened when you tried it out?

Re: [HD Pg 108, Sec. 4.3.2 - assigning-arrays-of-primitives-to-object-variables]

Posted: Wed Jul 21, 2021 1:30 pm
by enthunoob
Both compiled! :)