i have a question on whether the use of using primitive data type as opposed to their wrapper counter parts have any due effects on their serialization?
For example, i have a class Person
public class Person implements Serializable{
private int age;
}
as opposed to
public class Person implements Serializable{
private Integer age;
}
What are their differences?
I’m speaking in terms of Java’s Serialization:
While
intis a primitive type, which stores only the value of the variable (in binary), theIntegerobject (usingObjectOutputStream) will store some “metadata” that when deserialization occurs, it will see theIntegerobject.Yes, serialization not only stores the object, but also the states of the object, so if you store,
The value is “wrapped” (lack of better word) inside
Integerand the whole object is stored.Added note: In order not to store an object/variable, mark the field with a
transient, .e.gRelated Resources: