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: 25057
Because an array of anything is in itself an Object.
Sebastian Janisch
Ranch Hand
Joined: Feb 23, 2009
Posts: 1169
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: 701
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: 1169
I hate being only seconds late !! ;-)
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 25057
I usually find Rob Prime is a few seconds ahead of me
This message was edited 1 time. Last update was at Jan 05, 2010 14:13:32 by Campbell Ritchie
W. Joe Smith
Ranch Hand
Joined: Feb 10, 2009
Posts: 701
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: 17259
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
This message was edited 1 time. Last update was at Jan 05, 2010 15:30:59 by Anu Kota
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted Jan 05, 2010 18:53:11
0
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: 25057
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: 25057
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