• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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
 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic