• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing Serializable

 
Yed Su
Greenhorn
Posts: 10
Chrome Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it mandatory to implement Serializable interface if an object is to be serialized ? I worked with ObectInput/ObjectOutput and FileInput/FileOutput without implementing Serializable interface for my class and it worked perfect. Just curious to understand the Serializable.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Yes, to be serialized, a class must be marked Serializable. If you observed otherwise, I suspect either (1) you weren't actually using serialization, or (2) your classes inherited Serializable from a parent class.
 
Yed Su
Greenhorn
Posts: 10
Chrome Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest,

But I dont have any super class and Im using serialization as well. Please check the following example:

 
Henry Wong
author
Marshal
Pie
Posts: 21016
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hashtable instances, along with String, Integer, and Double instances are all Serializable -- try putting something that is not serializable into that hashtable.

Henry
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hashtable, String, Integer, and Double all implement Serializable, so all the objects you're writing are, indeed, serializable.
 
Yed Su
Greenhorn
Posts: 10
Chrome Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest and Henry Thanks for making me realize Serialize.. !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic