不必要地实施Serializable会受到什么惩罚? [英] What is the penalty for unnecessarily implementing Serializable?

查看:191
本文介绍了不必要地实施Serializable会受到什么惩罚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为我的分布式系统类开发Java RMI应用程序。

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

在讲座中,教授强调只允许类实现 Serializable ,这些 Serializable 必须通过网络传递值。

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

这意味着让太多的类实现 Serializable 会有一些缺点或惩罚。不需要通过网络发送的类。

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.

推荐答案


不必要地实施Serializable会受到什么惩罚?

What is the penalty for unnecessarily implementing Serializable?

不必要地实现 Serializable 不会受到惩罚。如果你从不序列化对象,那么只是因为你添加实现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.

为什么教授强调这是一个谜。问他。除了序列化之外没有其他开销,如果你通过RMI按值传递对象,你没有任何选择但是来实现 Serializable ,所以没有什么可以评估开销。这没有意义。

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.

这篇关于不必要地实施Serializable会受到什么惩罚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆