What is the penalty for unnecessarily implementing Serializable?

前端 未结 4 471
天命终不由人
天命终不由人 2020-12-11 17:23

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 Seriali

4条回答
  •  爱一瞬间的悲伤
    2020-12-11 17:38

    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.

提交回复
热议问题