• 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

Serialization

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,
Does serialization work with inner classes? Meaning if I have a class say Outer and there is an inner class called Inner can then we use the writeObject and readObject methods on the outer class to serialize it? Or should we be implementing the serializable interface in the inner class as well?
I can post the sample code if anyone needs to have a peek at it

Thanks for the help in advance

Regards
Prahalad
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think (though not sure) that inner classes implicitly extends everything from outer class and acts like just another member of outer class. So if outer class implements Serialization, inner classes will also have the facility to get serialized.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think inner class considered to be an member of outer class. So If you want to serialize outer class then inner class also must implement the serializable interface.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Inner class is also a class, so it must implement Serializable to be eligible for writig.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kalpesh Jain posted November 14, 2006 01:35 PM

I think (though not sure) that inner classes implicitly extends everything from outer class.


That seems to be a common mistake. The inner class is totally independent from the outer regarding inheritance!


eg.


prints false


and
System.out.println(inner instanceof Outer);
won't even compile.


Yours,
Bu.
 
reply
    Bookmark Topic Watch Topic
  • New Topic