IntelliJ open source
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Beginning Java
 
RSS feed
 
New topic
Author

Arrays of Objects

Anoo Kota
Greenhorn

Joined: Dec 30, 2009
Messages: 20

Hello,

Why doesn't this flag a compilation error?


Thanks in advance for your help.

Campbell Ritchie
Bartender

Joined: Oct 13, 2005
Messages: 14987

Because an array of anything is in itself an Object.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Messages: 1067

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

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

I hate being only seconds late !! ;-)

JDBCSupport - An easy to use, light-weight JDBC framework -
Campbell Ritchie
Bartender

Joined: Oct 13, 2005
Messages: 14987

I usually find Rob Prime is a few seconds ahead of me

This message was edited 1 time. Last update was at by Campbell Ritchie

W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Messages: 486

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

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

Thank You

This message was edited 1 time. Last update was at by Anu Kota

David Newton
Author
Bartender

Joined: Sep 29, 2008
Messages: 6873

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

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

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

have a look here!

SCJP 6 in progress......!!!!!!.
Campbell Ritchie
Bartender

Joined: Oct 13, 2005
Messages: 14987

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

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......!!!!!!.
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Beginning Java
 
RSS feed
 
New topic
JProfiler
Get rid of your performance problems and memory leaks!

.