IntelliJ Java IDE
The moose likes Beginning Java and the fly likes Arrays of Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Arrays of Objects" Watch "Arrays of Objects" New topic
Author

Arrays of Objects

Anup Om
Ranch Hand

Joined: Dec 30, 2009
Posts: 62
Hello,

Why doesn't this flag a compilation error?


Thanks in advance for your help.


SCJP6
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 26710
Because an array of anything is in itself an Object.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1173
neither would this


It's because an object array is an object.


JDBCSupport - An easy to use, light-weight JDBC framework -
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
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.


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1173
I hate being only seconds late !! ;-)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 26710
I usually find Rob Prime is a few seconds ahead of me
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
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
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18365

I believe JR is located in the US of A, so both Campbell and me live across the great pond.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Anup Om
Ranch Hand

Joined: Dec 30, 2009
Posts: 62
Thank You
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12612
I live near a tiny pond.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

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? .........


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 26710
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

Joined: Nov 04, 2009
Posts: 2066

have a look here!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 26710
Abimaran Kugathasan wrote:have a look here!
Thank you. It is useful to quote such links.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Campbell Ritchie wrote:
Abimaran Kugathasan wrote:have a look here!
Thank you. It is useful to quote such links.


You are welcome!
 
 
subject: Arrays of Objects
 
Threads others viewed
Trying to understand Array
Another garbage collection question
casting problem.
Assigning double dimension array to single dimension array of type Object
how is this correct
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture