Arsalan Khan
Arsalan Khan

Reputation: 51

What information does a serialized object store?

I have been working on a program and well i dont know what i can do with an object i retrieved by deserializing a file.

Can i say

  retrievedObject.MethodInClass()

will this above edit the retrieved object ?

When an object is serialized , does it only store the arguments or does it store the results as well. For example what does it store from the code below

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:

does it store k as 5 or as null ?

Upvotes: 1

Views: 33

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533750

When you serialize an object, it stores the class and the value of the fields in that object.

It doesn't store anything to do with the methods (if you ignore the serialVersionUID)

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

Neither, for example, this method will not alter what the object stores when serialized.

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

It stores the fields i, j, k

does it store k as 5 or as null ?

An int is a primitive so it can't be null. If k is 5 it will store this information, which method you called to make it 5 doesn't matter.

Upvotes: 2

Related Questions