• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to create object as Serializable?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,

How to make a object as Serializable..
For Example i got an object(Where the class didn't serializable) in main Class ... i have to serializable this object..

Can anyone help me ?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just make the class implement the interface Serializable:

Note that the interface doesn't have any methods, so you don't need to implement any methods.

Note: If you cannot modify the class, then it's not going to be possible. You can't make any object serializable.
[ June 23, 2008: Message edited by: Jesper Young ]
 
Marshal
Posts: 80140
418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More a beginner's question.

In theory it is easy; you just add "implements Serializable" after the class name. Serializable is a tagging interface (also called a marker interface) which has no methods.

In practice you need to ensure that all its fields are instances of Serializable classes too.
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic