Author
Arrays of Objects
Anoo Kota
Greenhorn
Joined: Dec 30, 2009
Messages: 20
posted Jan 05, 2010 14:05:32
Hello,
Why doesn't this flag a compilation error?
Thanks in advance for your help.
Campbell Ritchie
Bartender
Joined: Oct 13, 2005
Messages: 14987
posted Jan 05, 2010 14:08:01
Because an array of anything is in itself an Object.
Sebastian Janisch
Ranch Hand
Joined: Feb 23, 2009
Messages: 1067
posted Jan 05, 2010 14:08:19
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
Messages: 486
posted Jan 05, 2010 14:10:15
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
Messages: 1067
posted Jan 05, 2010 14:11:22
I hate being only seconds late !! ;-)
JDBCSupport - An easy to use, light-weight JDBC framework -
Campbell Ritchie
Bartender
Joined: Oct 13, 2005
Messages: 14987
posted Jan 05, 2010 14:13:23
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
Messages: 486
posted Jan 05, 2010 14:18:29
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.......
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."
Rob Prime
Bartender
Joined: Oct 27, 2005
Messages: 8837
posted Jan 05, 2010 14:25:45
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
Anoo Kota
Greenhorn
Joined: Dec 30, 2009
Messages: 20
posted Jan 05, 2010 15:28:37
Thank You
This message was edited 1 time. Last update was at Jan 05, 2010 15:30:59 by Anu Kota
David Newton
Author
Bartender
Joined: Sep 29, 2008
Messages: 6873
posted Jan 05, 2010 18:53:11
I live near a tiny pond.
Consultant/Trainer | Polyglottal Developer | Struts Committer/PMC | Struts 2 Web Application Development
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Messages: 304
posted Feb 08, 2010 10:10:55
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? .........
SCJP 6 in progress......!!!!!!.
Campbell Ritchie
Bartender
Joined: Oct 13, 2005
Messages: 14987
posted Feb 08, 2010 10:27:29
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
Messages: 304
posted Feb 09, 2010 22:36:56
have a look here!
SCJP 6 in progress......!!!!!!.
Campbell Ritchie
Bartender
Joined: Oct 13, 2005
Messages: 14987
posted Feb 10, 2010 03:33:06
Abimaran Kugathasan wrote: have a look
here!
Thank you. It is useful to quote such links.
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Messages: 304
posted Feb 10, 2010 04:24:26
Campbell Ritchie wrote:
Abimaran Kugathasan wrote: have a look
here!
Thank you. It is useful to quote such links.
You are welcome!
SCJP 6 in progress......!!!!!!.