| Author |
Implementing Serializable
|
Yed Su
Greenhorn
Joined: Mar 02, 2011
Posts: 10
|
|
|
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
Joined: Jul 08, 2003
Posts: 24056
|
|
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.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Yed Su
Greenhorn
Joined: Mar 02, 2011
Posts: 10
|
|
Thanks Ernest,
But I dont have any super class and Im using serialization as well. Please check the following example:
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16690
|
|
Hashtable instances, along with String, Integer, and Double instances are all Serializable -- try putting something that is not serializable into that hashtable.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24056
|
|
Hashtable, String, Integer, and Double all implement Serializable, so all the objects you're writing are, indeed, serializable.
|
 |
Yed Su
Greenhorn
Joined: Mar 02, 2011
Posts: 10
|
|
|
Ernest and Henry Thanks for making me realize Serialize.. !
|
 |
 |
|
|
subject: Implementing Serializable
|
|
|