Thomas Vanhelden Thomas Vanhelden - 5 months ago 60
Java Question

What is the penalty for unnecessarily implementing Serializable?

I need to develop a Java RMI application for my distributed systems class.

During the lecture, the professor was stressing to only let classes implement Serializable that have to be passed by value over the network.

This implies that there is some downside or penalty to letting too many classes implement Serializable. Classes that don't require to be sent over the network.

I don't see how there could be any downside since the serialization/deserialization would never happen if you never actually send it over the network.


What is the penalty for unnecessarily implementing Serializable?

There is no penalty for unnecessarily implementing Serializable. If you never serialize the object, nothing happens just because you added implements Serializable. If you do serialize it, it works instead of failing. That's not a penalty.

Why the professor was stressing that is a mystery. Ask him. There is no overhead other than when serializing, and if you're passing objects by value via RMI you don't have any choice but to implement Serializable, so there is nothing to evalute the overhead against. It is meaningless.