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 (?)
[HD Pg 108, Sec. 4.3.2 - assigning-arrays-of-primitives-to-object-variables]
Moderator: admin
-
- Posts: 60
- Joined: Thu Apr 15, 2021 12:21 pm
- Contact:
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 108, Sec. 4.3.2 - assigning-arrays-of-primitives-to-object-variables]
What happened when you tried it out?
If you like our products and services, please help us by posting your review here.
-
- Posts: 60
- Joined: Thu Apr 15, 2021 12:21 pm
- Contact:
Who is online
Users browsing this forum: No registered users and 47 guests