尽管Java中的Serializable接口没有方法,没有字段,但可以实现其功能。怎么样? [英] Although the Serializable interface in Java has no methods, no fields, it can achieve its function. How?

查看:153
本文介绍了尽管Java中的Serializable接口没有方法,没有字段,但可以实现其功能。怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管java.io.Serializable接口公共接口Serializable {} 令人惊讶地没有包含Java中的任何方法和字段,但是实现此接口的类却能够实现序列化和反序列化的功能(对象被序列化或反序列化的状态)。它如何在Java中没有任何方法或字段的情况下实现序列化和反序列化的功能?

Although the java.io.Serializable interface public interface Serializable{} surprisingly doesn't contain any methods and fields in Java, the class that implements this interface is able to achieve the function of serialization and deserialization (the state of the object being serialized or deserialized). How can it achieve the function of serialization and deserialization without any methods or fields in Java?

推荐答案

某些接口仅充当标记

通过反射访问UID和自定义读取器/写入器。

The UID and custom readers/writers are accessed via reflection.

Serializable 是一个标记,JRE / JVM可能会根据其存在来采取措施。

Serializable is a marker, and the JRE/JVM may take action(s) based on its presence.

http://en.wikipedia.org/wiki/Marker_interface_pattern

这篇关于尽管Java中的Serializable接口没有方法,没有字段,但可以实现其功能。怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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