java - 序列化对象存储什么信息?

标签 java serialization deserialization

我一直在开发一个程序,但我不知道我可以用通过反序列化文件检索到的对象做什么。

我可以说

  retrievedObject.MethodInClass()

上面的内容会编辑检索到的对象吗?

当一个对象被序列化时,它是只存储参数还是也存储结果。例如,下面的代码存储了什么内容

int i;
int j;
int k
public setNumber(int i, int j){ // where i is 2 and j is 3
this.i = i
this.j = j }
k = i+j:

它将 k 存储为 5 还是 null ?

最佳答案

当您序列化一个对象时,它会存储该对象中的类和字段值。

它不存储与方法相关的任何内容(如果您忽略serialVersionUID)

When an object is serialized , does it only store the arguments or does it store the results as well.

例如,此方法不会改变对象在序列化时存储的内容。

public setNumber(int i, int j){ // where i is 2 and j is 3
  int a = i;
  int b = j; 
  int c = i+j:
}

For example what does it store from the code below

它存储字段ijk

does it store k as 5 or as null ?

int 是一个基元,因此它不能为 null。如果 k5 ,它将存储此信息,您调用哪个方法使其变为 5 并不重要。

关于java - 序列化对象存储什么信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27584327/

相关文章:

Java : when do you want to customize the serialization process?

java - 解析数组并提取相同长度的字符串

java - 当应用服务器需要重启时,针对哪个文件类型改变?

java - Java序列化是缩小内存占用的工具吗?

c# - 将难以形成的 XML 反序列化为 C# 对象

c++ - 二进制反序列化 - 如何找到它是什么类型的序列化?

java - 反序列化ArrayList中的对象

java - 如何集中 primefaces 菜单栏?

java - 创建 Java native 接口(interface)的问题

javascript - 如何在使用 ajax 时将 javascript 对象传递给 PHP 文件