• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

array question

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
reply
    Bookmark Topic Watch Topic
  • New Topic