• Post Reply Bookmark Topic Watch Topic
  • New Topic

Arrays of Objects  RSS feed

 
Anup Om
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Why doesn't this flag a compilation error?


Thanks in advance for your help.

 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because an array of anything is in itself an Object.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
neither would this


It's because an object array is an object.
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I am reading the code correctly, you have an array of objects, o[], containing a single element. That element is an Object array of arrays.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hate being only seconds late !! ;-)
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I usually find Rob Prime is a few seconds ahead of me
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Must be that delay for the information to cross the pond .

Actually, come to think of it, I don't know if Rob lives across the pond or not....or, for that matter, if JR is hosted across the pond.......
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe JR is located in the US of A, so both Campbell and me live across the great pond.
 
Anup Om
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I live near a tiny pond.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, All.......

It's said that in K&B's book,


When you assign an array to a previously declared array reference, the array you're assigning must be the same dimension as the reference you're assigning it to. ...




Then these line are wrong? .........
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The bit about two-d is wrong. There is no such thing as a 2-D array in Java. Look at the Java™ Tutorials, where it says it's an array of arrays.
A reference must be declared and assigned the same type. An int[] is different from an int[][], but both count as objects. And an int isn't an object. You can assign squeegees[0] to blots (or vice versa) because they are both the same type, viz int[]. Both are however null in the code you quoted.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have a look here!
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abimaran Kugathasan wrote:have a look here!
Thank you. It is useful to quote such links.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Abimaran Kugathasan wrote:have a look here!
Thank you. It is useful to quote such links.


You are welcome!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!