java - How does overriding of readObject() and writeObject() methods under the serializable interface, find its application in real life development?
问题描述
So, I was studying serialization and I got to know about us having the ability to override the above stated methods.I was wondering,how could I use it? One idea that came to my mind is maybe encrypting and decrypting the data while writing and reading.I am not sure though,if it is how it finds its application. As a developer, how would you use it?
解决方案
因此,在进一步的研究中,我发现了在 Serialization 接口下覆盖readObject()和writeObject()方法的应用程序,由于性能开销,它在 Android 开发中具有重要用途。
所以,JAVA中的Serializable接口在内部使用反射来序列化对象。反射导致创建大量对象,因此具有很大的性能开销。但是如果给定的方法被覆盖,以最大限度地减少垃圾收集费用,序列化读取和写入可以显着更快地执行。
例如,Android 允许实现Parcelable接口,该接口试图取消反射。正如预期的那样,它在方法的默认实现中表现得更好。但可以观察到,在覆盖 readObject() 和 writeObject() 方法时它比默认的快得多。
推荐阅读
- html - flutter webview 不允许我在任何端口上打开 localhost
- angular - 重定向到同一页面后如何显示以前的输入文本
- java - 使用带有 twitter4j 的 java 应用程序发布推文时出现连接超时
- wcf - 作为本地系统运行的 Windows 服务如何被授予访问 SSL 证书的权限?
- kubernetes - 无法将卷挂载到 Kubernetes 中的 pod
- react-native - 如何仅在 MacOS 上运行 npm postinstall 脚本
- reactjs - 如何通过使用功能组件更新 React 中的状态来重新渲染页面。?
- mysql - 不同结构的总和给出相同的结果MYSQL
- microsoft-teams - Microsoft 团队 - 用户无法从“帖子”选项卡下收到的通知导航到自定义频道选项卡
- jenkins - 查找运行时间超过 24 小时的 Jenkins 工作