• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array question

 
Douglas Chorpita
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java, an Monkey array can be assigned to an animal array.

The following code is legal:




Java doesn't allow this, however. Why? Is "Object" a special case?

 
Andy Morris
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both code snippets are completely legal and will compile and run without errors. I don't know how you reached your observation.

The only arrays where implicit casting is not permitted are arrays referencing primitives types.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andy Morris:
Both code snippets are completely legal and will compile and run without errors. I don't know how you reached your observation.

The only arrays where implicit casting is not permitted are arrays referencing primitives types.


Confirmed.
 
Douglas Chorpita
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry. My fault.

I was doing a bunch of tests, all in one file.

I had created a class called "Object" in my own package. I know this is stupid, but I wanted to see (with my own eyes) that a class called "Object" would compile and extend "java.lang.Object".

This is why I got the error.

Thanks for the help!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic