• 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

Conversion of Objects

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can someone help me in under standing following rules for the conversion of objects

an object of "Oldtype" is to be converted to an object of "Newtype"

1) If an "Oldtype" is an interface and "NewType" is a class "Newtype" should be object
2) If an "Oldtype" is an array and "NewType" is a class "Newtype" should be object
3) If an "Oldtype" is an array and "NewType" is an interface "Newtype" should Cloneable or Serializable
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most Important! Objects do NOT get converted or cast. Object references get cast. Some primitives can get converted.
1) casting an interface reference
You can cast an interface reference to Object or to an interface that is a parent of the interface. Thats because everything descends from Object, and interfaces can have a hierarchy.
2) an array reference can be cast to Object class reference
3) an array reference can be cast to Cloneable interface
and Serializable interface if its a primitive array, but I don't remember if reference arrays can be cast to Serializable.
Bill
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic