简体   繁体   English

通过添加静态方法来更改可序列化的类,java

[英]altering a serializable class by adding static methods, java

My serializable class is not getting read in with objectinputstream after adding static methods to the class, is this expected behavior? 将静态方法添加到类后,我的可序列化类未使用objectinputstream读取,这是预期的行为吗? Where in the javadoc does it state adding static methods to a serializable class creates incompatibility? 它在javadoc中的哪个位置声明将静态方法添加到可序列化的类中会导致不兼容?

In the Java Object Serialization Specification, section 4.6 : 在Java对象序列化规范的4.6节中:

The stream-unique identifier is a 64-bit hash of the class name, interface class names, methods, and fields. 流唯一标识符是类名称,接口类名称,方法和字段的64位哈希值。

... ...

For each non-private method sorted by method name and signature: 对于按方法名称和签名排序的每个非私有方法:

  • The name of the method. 方法的名称。
  • The modifiers of the method written as a 32-bit integer. 方法的修饰符,写为32位整数。
  • The descriptor of the method. 方法的描述符。

No, I can't work out how it could actually break compatibility of serialized state either, but this is why it's either worth avoiding the default Java binary serialization (eg for Protocol Buffers ) or always declaring a serialVersionUid yourself. 不,我不能工作了它如何能真正打破序列化状态的兼容性要么,但是这就是为什么它要么值得避免了默认的Java二进制序列(如协议缓冲区 ), 总是声明serialVersionUid自己。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM