gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:37:08 25 4
gpt4 key购买 nike

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

我可以说

  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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com