aspose file tools*
The moose likes Java in General and the fly likes Is there any cost associated with the implementation of Serializable interface? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Is there any cost associated with the implementation of Serializable interface?" Watch "Is there any cost associated with the implementation of Serializable interface?" New topic
Author

Is there any cost associated with the implementation of Serializable interface?

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 516
    
    2



We know that, if we anticipate objects are passed by value over a remote method calls, or should we choose to serialize/deserialize the objects or want to save the object as a bytes to some file (and many other usecases), we are required to have our class implement Serializable. But lately I was just curious, if any cost is associated with the implementation of this marker interface. What if, we do not have any such requirements that are needed for Serialization, but still want to make it a serializable. I understand that there is no need to do anything that is absolutely not needed, but what if decide to make it Serializable. Would this decision cause some sort of unexpected behaviour?


Regards
KumarRaja

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18113
    
    8

Do you mean behaviour which you would not expect, or behaviour which somebody else would not expect?

Obviously we have no way of predicting what you might expect.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3362
    
    9
I avoid Serializable like the plague. It completely breaks all encapsulation. Instead, if I want to save my objects, I usually add a methods like this to my class:
Or in the case of immutable objects:
Serializable makes your class' private fields part of the specification, which is absolutely horrible.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

In that case, it would probably be a good idea to implement Externalizable. That way you get the benefits of it being Serializable (e.g. works with ObjectOutputStreams), but the class controls the read/write.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there any cost associated with the implementation of Serializable interface?
 
Similar Threads
serialization in java
Object & Serializable
Serializable interface.
publish a Servlet as an SOA implementation?
regarding marker interfaces