Java course assignment:
when a variable is put transient will serialisation ignore the variable or only the value of the variable.
Test this.
How do I test this?
Java course assignment:
when a variable is put transient will serialisation ignore the variable or only the value of the variable.
Test this.
How do I test this?
Do something like:
public class Test1 implements Serializable {
private long longValue;
}
public class Test2 implements Serializable {
private long longValue;
private transient int intvalue;
}
now serialize an instance of each to disk, if the sizes are the same, then you know that transient variable is not serialized at all, otherwise....
If a variable is declared transient it will not be serialized(not stored in bytes stream as state of the Object).
On Deserialization it will get the default value.
If you don't want to serialize a variable declare it as transient. Serialization means saving the state of a variable. see here for detailed example.